1. 程式人生 > >MYSQL:HAVING

MYSQL:HAVING

SELECT子句及其順序:

SELECT -- FROM --  WHERE -- GROUP BY -- HAVING -- ORDER BY -- LIMIT

HAVING 用於GROUP BY之後,常一起搭配使用。

HAVING 是在GROUP BY 分組之後的二次篩選。


 栗子:


程式碼:

select title,count(title) as t from titles group by title having t>=2;


程式碼;

select  title,  count( distinct emp_no ) as t from titles  group by title having t>=2;