At 4:49 PM +0200 10/9/01, Rafal Jank wrote:
>Martin Eriksson wrote:
>>
>> I want to run a query that gathers the sum from the columns where the key
>> items are equal:
>> Example: From this table...
>> key price
>> 1 50
>> 1 70
>> 2 60
>> 3 60
>> 3 40
>>
>> ..I want this:
>>
>> key price
>> 1 120
>> 2 60
>> 3 100
>select key,sum(price) group by key order by key;
In MySQL, if the GROUP BY and ORDER BY name the same columns, you can
drop the ORDER BY. So it's possible to make the query a bit shorter.
(Note that this won't necessarily be true for other DBMS engines.
>
>
>
>sql,table
>--
>_/ _/ _/_/_/ ----- Rafa? Jank yankee@stripped -----
> _/ _/ _/ _/ _/ Wirtualna Polska SA http://www.wp.pl
> _/_/_/_/ _/_/_/ ul. Uphagena 2, 80-237 Gdansk, tel/fax. (58) 5215625
> _/ _/ _/ --------==* http://szukaj.wp.pl *==----------
--
Paul DuBois, paul@stripped