What! What?

Wal McConnell

HAVING SQL clause

I've been using the HAVING clause to simplify my SQL queries. It allows you to specify a condition for an aggregate function used in the SELECT list (doing so in the WHERE clause is illegal).

So to find the politicians who are receiving a total of more than $50,000 of expenses

	
		SELECT politician, SUM(payment) 
		FROM expences 
		GROUP BY politician 
		HAVING SUM(payment) > 50000;	

Nice!