如何按周或按月汇总付款?

时间:2014-10-07 16:34:20

标签: sql firebird

我有这张桌子:

date        payment
----        -------
1/1/2014    2000
13/1/2014   1200
2/3/2014    1900
3/4/2014    1800
....        ....
....        ....

我想计算每周付款:

date      payment
-----     -------
week1     sum(week1)
week2     sum(week2)
....      .....

或每月:

date      payment
-----     ------ 
month1     sum(month1) 
month2     sum(month2)
.....      .....

1 个答案:

答案 0 :(得分:3)

select extract(week from date) as week,
       sum(payment) as payments
from your_table
group by week