开发者

making daily report with MySQL

i want to make some daily report which order by date. i want this data can increase every day.

Date            qty       QP
2010-09-01       10       10 
2010-09-02       3        13  (it means result QP from 2010-09-01 accumulate with 2010-09-02)
2010-09-03       8        21

this is the 1st code:

SELECT Date, SUM(number) AS qty FROM calc GROUP BY Date

how do i do to show "QP" if for actually i dont need to show "qty" field(automatic count) just show Date and QP but it still ca开发者_开发技巧n count?


SET @r := 0;
SELECT  date, @sum := SUM(number) AS qty, @r := @r + @sum AS qp
FROM    calc
GROUP BY
        date


This example will help you for sure:

MySQL select "accumulated" column

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜