having 的用法
聚合函数
where 后面不能直接使用聚合函数
处理函数
题目
编写一个 SQL 查询,查找 Person 表中所有重复的电子邮箱。
示例:
+----+---------+
| Id | Email |
+----+---------+
| 1 | a@b.com |
| 2 | c@d.com |
| 3 | a@b.com |
+----+---------+
根据以上输入,你的查询应返回以下结果:
+---------+
| Email |
+---------+
| a@b.com |
+---------+
说明:所有电子邮箱都是小写字母。
1、使用having过滤分组select email from person group by email having count(email) > 1
2、使用临时表方法select email from (select email,count(email) as num from person group by eamil) as new where new.num >1
说明
1、having通常用在聚合函数前面,对聚合函数进行过滤,(MAX、MIN、COUNT、SUM)
2、having通常和group by 一起连用,因为where不能加在group by的后面
3. where 和 having 的区别?
1. where 在分组之前进行限定,如果不满足条件,则不参与分组。having在分组之后进行限定,如果不满足结果,则不会被查询出来
2. where 后不可以跟聚合函数,having可以进行聚合函数的判断。
mysql执行语句顺序,严格遵循次顺序,不能改变
select
from
where
group by
having
order by
having 的用法的更多相关文章
- EditText 基本用法
title: EditText 基本用法 tags: EditText,编辑框,输入框 --- EditText介绍: EditText 在开发中也是经常用到的控件,也是一个比较必要的组件,可以说它是 ...
- jquery插件的用法之cookie 插件
一.使用cookie 插件 插件官方网站下载地址:http://plugins.jquery.com/cookie/ cookie 插件的用法比较简单,直接粘贴下面代码示例: //生成一个cookie ...
- Java中的Socket的用法
Java中的Socket的用法 Java中的Socket分为普通的Socket和NioSocket. 普通Socket的用法 Java中的 ...
- [转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法
一.C#中MessageBox.Show用法 MessageBox.Show (String) 显示具有指定文本的消息框. 由 .NET Compact Framework 支持. MessageBo ...
- python enumerate 用法
A new built-in function, enumerate() , will make certain loops a bit clearer. enumerate(thing) , whe ...
- [转载]Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法总结
本文对Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法进行了详细的总结,需要的朋友可以参考下,希望对大家有所帮助. 详细解读Jquery各Ajax函数: ...
- 【JavaScript】innerHTML、innerText和outerHTML的用法区别
用法: <div id="test"> <span style="color:red">test1</span> tes ...
- chattr用法
[root@localhost tmp]# umask 0022 一.chattr用法 1.创建空文件attrtest,然后删除,提示无法删除,因为有隐藏文件 [root@localhost tmp] ...
- 萌新笔记——vim命令“=”、“d”、“y”的用法(结合光标移动命令,一些场合会非常方便)
vim有许多命令,网上搜有一堆贴子.文章列举出各种功能的命令. 对于"="."d"."y",我在无意中发现了它们所具有的相同的一些用法,先举 ...
- [转]thinkphp 模板显示display和assign的用法
thinkphp 模板显示display和assign的用法 $this->assign('name',$value); //在 Action 类里面使用 assign 方法对模板变量赋值,无论 ...
随机推荐
- jenkins动态参数插件Dynamic Parameter安装及简单使用
插件安装: 1.先下载插件hpi文件到本地 jenkins插件下载地址 http://mirror.xmission.com/jenkins/plugins/ http://updates.jen ...
- django models实际操作中遇到的一些问题
问题1.将主键id改成自动生成的python3 manage.py migrate时报下面的错误 django.db.utils.InternalError: (1091, "Can't D ...
- mysqlli
./configure --with-mysql=/usr/bin/mysql_config \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd ht ...
- redis.clients.jedis.exceptions.JedisException: Can connect to sentinel, but seems to be not monitored.
在使用Redis的哨兵Sentinel配置时,报错如下: redis.clients.jedis.exceptions.JedisException: Can connect to sentinel, ...
- harbor在centos7.4下面配置自签名证书(域名是端口映射)
1.harbor安装,按常规安装. 注意事项,端口映射 端口要外网的与内网一至. 配置文件修改 vim docker-compose.yml proxy: image: vmware/nginx-ph ...
- centos 6 KVM 网卡桥接配置
一. 网卡桥接前准备 1.软件支持: # rpm -qa bridge-utils # yum install bridge-utils 确保软件包已安装 2. 关闭NetworkMana ...
- Serializers序列化组件
Django的序列化方法 .values 序列化结果 class BooksView(View): def get(self, request): book_list = Book.objects.v ...
- 187. Repeated DNA Sequences (String; Bit)
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
- HDU 1698 Just a Hook(线段树区间更新查询)
描述 In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes ...
- [剑指Offer]23-链表中环的入口节点
题目链接 https://www.nowcoder.com/practice/253d2c59ec3e4bc68da16833f79a38e4?tpId=13&tqId=11208&t ...