|
Posted by damezumari on 08/18/07 09:02
How do I get the total without a condition and the total with the
condition at the same time?
This is my mysql table:
id datetimeconfirmed customerid amount
1 2007-08-14 06:19:03 1 12.25
2 2007-08-06 06:19:19 1 15
3 2007-08-02 06:19:41 2 5
4 2007-08-07 06:19:58 2 7.25
5 2007-08-09 06:36:41 3 25
If I run this query:
select customerid, sum(amount) from test
group by customerid
I get this result:
customerid sum( amount )
1 27.25
2 12.25
3 25
If I run this query:
select customerid, sum(amount) from test
where datetimeconfirmed < '2007-08-08'
group by customerid
I get this result:
customerid sum( amount )
1 15
2 12.25
Which query do I have to run to get this result?
customerid sum( amount ) total
1 15 27.25
2 12.25 12.25
3 NULL 25
Regards,
Jan Nordgreen
PS: I posted this question at comp.databases.mysql a week ago, but no
answers. I know this is a php question, but still.
Navigation:
[Reply to this message]
|