• having用法:

mysql中,当我们用到聚合函数,如sum,count后,又需要筛选条件时,having就派上用场了,因为WHERE是在聚合前筛选记录的,having在聚合后筛选记录having和group by是组合着用的。

引入 HAVING 是因为 WHERE 无法和统计函数一起使用

mysql语法:having,using

select cid,count(cid) as cids 
from t_person_info
where cid <> 1
group by cid
having cids>=2
order by cid DESC

mysql语法:having,using

  • using用法:

using()用于两张表的join查询,要求using()指定的列在两个表中均存在,并使用之用于join的条件。

 select a.*, b.* from a left join b using(colA);

等价于:

  select a.*, b.* from a left join b on a.colA = b.colA;

 

 

 

 

相关文章: