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