Quote:
|
Originally Posted by r937
SELECT custid
FROM ord
GROUP
BY custid
HAVING COUNT(*) =
SUM(CASE WHEN total > (SELECT AVG(total) FROM ord)
THEN 1 ELSE NULL END)
|
Here's yet an other query which returns the required result:
Code:
SELECT custid
FROM ord, (select avg(total) as average from ord) dv
GROUP BY custid, average
HAVING MIN(total) > average
It's closer to the original query of khdani (with the join to a 1x1 table).
The "MIN(total) >" clearly expresses that all totals within the same group (of orders for the same customer) need to be larger than something.