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 ipython in Cloudera VM using pip

install postgreSQL in ubuntu 16.04

Install MYSQL 5.6 in ubuntu 12.04/14.04 and set password and remote access