List:General Discussion« Previous MessageNext Message »
From:Ian Sales (DBA) Date:March 8 2005 9:24am
Subject:Re: Sum() unequal number of rows
View as plain text  
>"Dave Kennedy" <davek@stripped> wrote on 03/06/2005 05:09:36 PM:
>
>  
>
>>SELECT sum(col1) AS total1
>>FROM t1
>>GROUP by col1
>>
>>SELECT col1, sum(col2) AS total2
>>FROM t2
>>GROUP by col2
>>
>>Table t1 contains 4 rows to sum for each value in col1 
>>
>>Table t2 contains 8 rows to sum for each value in col2
>>
>>If one select statement is used, the result has 8 rows and total2 is
>>correct but the tota11 is summed over 8 rows instead of 4 
>>
>>How can they be joined to produce one row total1, total2 
>>    
>>
- UNION? (http://dev.mysql.com/doc/mysql/en/union.html)

-- 
+-------------------------------------------------------------------+
| Ian Sales                                  Database Administrator |
|                                                                   |
|                              "All your database are belong to us" |
| ebuyer                                      http://www.ebuyer.com |
+-------------------------------------------------------------------+

Thread
Sum() unequal number of rowsDave Kennedy6 Mar
  • Re: Sum() unequal number of rowsSGreen7 Mar
    • Re: Sum() unequal number of rowsEric Bergen7 Mar
    • Re: Sum() unequal number of rowsDBA)8 Mar