SQL : Using Count within the Where clause

As trying to make a condition inside an SQL where clause based on the COUNT function or other functions, the trivial one is to use :

SELECT count(items) as cnt from user_items where cnt>3

This is not going to work, and therefore you need to use the following one instead :

SELECT count(items) as cnt from user_items having count(items)>3

In case you want to add a where clause to the SQL statement, here is how it should look :

SELECT count(items) as cnt from user_items where id>1000 having count(items)>3

Leave a Reply


imed.ws - Imed Bouchrika Website© 2003-2007.