You are here: Re: Total without and with a condition « PHP Programming Language « IT news, forums, messages
Re: Total without and with a condition

Posted by Paul Lautman on 08/18/07 11:00

damezumari wrote:
> 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.

Answered over on comp.databases.mysql

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация