问题:
比如记录2007-02-01有3条,2007-02-02有5条,2007-02-03有4条
我要取2007-02-01对应3条的和,2007-02-02对应8条的和,2007-02-03对应12条的和 就是取该记录与该记录前面所有记录的字段值的和
结果如下: 2007-02-01 3条 300 2007-02-02 5条 500 2007-02-03 12条 1200
测试表: test
today fee
2007-02-01 100
2007-02-01 100 2007-02-02 100
2007-02-02 100 2007-02-03 100
2007-02-03 100
sql:
select a.today, sum(b.newfee) from (select distinct(today) from test) a,
(select today,sum(fee) as newfee from TEST group by today)
b where b.today<=a.today group by a.today order by a.today desc