
December 9th, 2003, 12:11 PM
|
|
Junior Member
|
|
Join Date: Nov 2003
Location: Vancouver, WA
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Compare Aggregates
I have two SQL queries which work one provides the avg number of sales by department and one which shows the total sales by dept. I am trying to combine the queries to show the deptartments that sold less than the average:
SELECT deptname, SUM(saleqty)
FROM qsale
WHERE saleqty < (SELECT SUM(saleqty) / COUNT (DISTINCT deptname)
FROM qsale)
GROUP BY deptname
I'm trying to understand how to do this comparison. The saleqty in my WHERE clause does not reflect the SUM(saleqty). How should this be formatted?
|