Hacker News new | ask | show | jobs
by sudomake 2990 days ago
You dont need include aggregate functions in your select clause to use them in having and order by.

I suppose I may be glossing over another point, but for the subquery example I would've just done:

SELECT first_name, last_name, email FROM customer WHERE customer_id IN (SELECT DISTINCT customer_id FROM payment WHERE extract(month from payment_date) = 4 AND extract(day from payment_date) BETWEEN 10 AND 13 GROUP BY customer_id HAVING SUM(amount) > 30 ORDER BY SUM(amount) DESC LIMIT 5);