sql按月汇总

2024-10-22 15:29:30
推荐回答(3个)
回答1:

按月份
select sum(money)
from A
group by Year,month
按季度
select ceil(month/3),sum(money)
from A
group by Year,ceil(month/3)

回答2:

按月汇总:
select sum(money),month from table group by month;

按季汇总:
select sum(money) from table where month in (1,2,3)
union
select sum(money) from table where month in (4,5,6)
union
select sum(money) from table where month in (7,8,9)
unoin
select sum(money) from table where month in (10,11,12);

回答3:

1、按月汇总:
SELECT year, month,
SUM(money)
FROM goods
GROUP BY year, month
ORDER BY year, month