List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:October 9 2001 3:38pm
Subject:Re: Is this possible in MySQL?
View as plain text  
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
Thread
Is this possible in MySQL?Martin Eriksson9 Oct
  • Re: Is this possible in MySQL?Rafal Jank9 Oct
    • Re: Is this possible in MySQL?Paul DuBois9 Oct
      • Re: Is this possible in MySQL?David Turner9 Oct
        • MySQL Client on WindowsFletcher Sandbeck9 Oct
          • Re: MySQL Client on WindowsMarjolein Katsma10 Oct
  • RE: Is this possible in MySQL?Chris Bolt9 Oct
  • RE: Is this possible in MySQL?Nicholas Gaugler9 Oct