tags:

views:

35

answers:

2

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 can count?

+1  A: 
SET @r := 0;
SELECT  date, @sum := SUM(number) AS qty, @r := @r + @sum AS qp
FROM    calc
GROUP BY
        date
Quassnoi
what is the meaning of @r??sory i'm newbie.
klox
@klox: it's a session variable. It is incremented on each row of the query and persists after the query is complete.
Quassnoi
@Quassnoi: how if i dont want to show "qty"? whether this code change?
klox
A: 

This example will help you for sure:

http://stackoverflow.com/questions/1135627/mysql-select-accumulated-column

Cheers,

Ramon Araujo