mysql having和using使用

Posted king西阳

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql having和using使用相关的知识,希望对你有一定的参考价值。

1、having
当用到聚合函数sum,count后,又需要筛选条件时,就可以考虑使用having,因为where是在聚合前筛选记录的,无法和统计函数一起使用,而having在聚合后筛选记录,可以和统计函数一起使用。having是和group by组合着用的。

SELECT
    cid,
    count(cid) AS cids
FROM
    t_person_info
WHERE
    cid <> 1
GROUP BY
    cid
HAVING
    cids >= 2 #count(cid)统计的结果 
ORDER BY cid DESC

2、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;

 

以上是关于mysql having和using使用的主要内容,如果未能解决你的问题,请参考以下文章

Mycat SqlServer Do not have slave connection to use, use master connection instead

kafkaThe group member needs to have a valid member id before actually entering a consumer group(代码片段

You can add an index on a column that can have NULL values if you are using the MyISAM, InnoDB, or M

ubuntu16.04 yum报错:There are no enabled repos. Run “yum repolist all“ to see the repos you have.(代码片段

bug之needs to have a value for field "id" before this many-to-many relationship can be used

持久片段和查看器