MySql查询当年1-12月数据
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')
上一篇: 【Go】go的日志框架-logrus初探
下一篇: 如何成为一名优秀的C程序员