Easy:

SELECT id FROM sales 
GROUP BY id
HAVING SUM( totalsales) <= 20000 ;

That will perform the grouping, by ID, then filter and display only
calculated rows with a sum less than 20000.

> -----Original Message-----
> From: Yoed Anis [mailto:[EMAIL PROTECTED] 
> Sent: Monday, July 28, 2003 10:22 AM
> To: [EMAIL PROTECTED]
> Subject: Search WHERE SUM
> 
> 
> Hello,
> 
> What would be the proper way of generating a query like the following;
> 
> SELECT id FROM sales WHERE SUM( totalsales) <= '20000' GROUP BY id;
> 
> Assuming the table looks like this;
> Sales:
> 
> Id| totalsales| monthyear
> 1 | 100       | 2003-09
> 1 | 10000     | 2003-08
> 1 | 2000      | 2003-07
> 2 | 30000     | 2003-05
> 3 | 10000     | 2003-06
> 3 | 10000     | 2003-05
> 
> I want the query to return id 1 and 2 as the sum of their 
> totalsales is smaller then 20000.
> 
> 
> Thanks for your help,
> Best,
> Yoed
> 
> 
> -- 
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    
> http://lists.mysql.com/mysql?> [EMAIL PROTECTED]
> 
> 


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to