欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

MySql查询当年1-12月数据

程序员文章站 2023-01-25 15:29:57
mysql查询当年1-12月数据。 select count(*) as jantradingvolume, coalesce(sum(tt.amount),0) as jana...

mysql查询当年1-12月数据。

select count(*) as jantradingvolume, coalesce(sum(tt.amount),0) as janamount,

(select count(*) from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-02')) as febtradingvolume,

(select coalesce(sum(tt.amount),0) from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-02')) as febamount,

(select count(*) from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-03')) as martradingvolume,

(select coalesce(sum(tt.amount),0) from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-03')) as maramount,

(select count(*) from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-04')) as aprtradingvolume,

(select coalesce(sum(tt.amount),0) from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-04')) as apramount,

(select count(*) from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-05')) as maytradingvolume,

(select coalesce(sum(tt.amount),0) from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-05')) as mayamount,

(select count(*) from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-06')) as juntradingvolume,

(select coalesce(sum(tt.amount),0) from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-06')) as junamount,

(select count(*) from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-07')) as jultradingvolume,

(select coalesce(sum(tt.amount),0) from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-07')) as julamount,

(select count(*) from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-08')) as augtradingvolume,

(select coalesce(sum(tt.amount),0) from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-08')) as augamount,

(select count(*) from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-09')) as septradingvolume,

(select coalesce(sum(tt.amount),0) from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-09')) as sepamount,

(select count(*) from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-10')) as octtradingvolume,

(select coalesce(sum(tt.amount),0) from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-10')) as octamount,

(select count(*) from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-11')) as novtradingvolume,

(select coalesce(sum(tt.amount),0) from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-11')) as novamount,

(select count(*) from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-12')) as dectradingvolume,

(select coalesce(sum(tt.amount),0) from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-12')) as decamount

from tt_trade tt

where date_format(tt.creationtime,'%y-%m') = concat(year(now()),'-01')