mysql tips - HAVING - another clause use to filter result like WHERE

Example:
correct usage:
SELECT c1, count(*) from t1 where Date like "2013-12-30 %" group by c1 HAVING count(*)>2 order by c1;

wrong usage:
SELECT c1, count(*) from t1 where Date like "2013-12-30 %" and count(*)>2  group by c1 order by c1;

Because the aggregate function can not be used in WHERE clause. WHERE clause is used to SELECT the rows. And aggregate functions are after WHERE, and before HAVING. HAVING clause is used to filter the select result.

Comments

Popular posts from this blog

install postgreSQL in ubuntu 16.04

timestamp with 16, 13 and 10 digits to Qlik date

install ipython in Cloudera VM using pip