LeetCode——Duplicate Emails(使用group by以及having解决分组统计结果)
Write a SQL query to find all duplicate emails in a table named Person.
+----+---------+
| Id | Email |
+----+---------+
| 1 | a@b.com |
| 2 | c@d.com |
| 3 | a@b.com |
+----+---------+
For example, your query should return the following for the above table:
+---------+
| Email |
+---------+
| a@b.com |
+---------+
Note: All emails are in lowercase.
题意:查找表中重复的Email.
此题是很典型的对分组结果进行统计筛选例题,因此可以利用group by进行分组,然后使用having统计.
# Write your MySQL query statement below
SELECT Email FROM Person GROUP BY Email HAVING COUNT(Email) > 1;
此处,对where与group by进行比较(引用自:https://leetcode-cn.com/problems/duplicate-emails/solution/cha-zhao-zhong-fu-de-dian-zi-you-xiang-by-he-qing-/):
where后不能跟聚合函数,因为where执行顺序大于聚合函数。where子句的作用是在对查询结果进行分组前,将不符合where条件的行去掉,即在分组之前过滤数据,条件中不能包含聚组函数,使用where条件显示特定的行。having子句的作用是筛选满足条件的组,即在分组之后过滤数据,条件中经常包含聚组函数,使用having条件显示特定的组,也可以使用多个分组标准进行分组。
LeetCode——Duplicate Emails(使用group by以及having解决分组统计结果)的更多相关文章
- [LeetCode] Duplicate Emails 重复的邮箱
Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...
- LeetCode - Duplicate Emails
Description:Write a SQL query to find all duplicate emails in a table named Person. 找出表中重复的Email. # ...
- sql group by hour 按小时分组统计
Time字段以小时分组统计 select datepart(hour,time) hour,count(1) count from table where Similarity<75 group ...
- sql leetcode -Duplicate Emails
第一种解法: select distinct p1.Email as Email from Person p1, Person p2 where p1.Email=p2.Email and p1.Id ...
- [LeetCode] Delete Duplicate Emails 删除重复邮箱
Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...
- Leetcode 182. Duplicate Emails
Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...
- LeetCode DB: Duplicate Emails
Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...
- [SQL]LeetCode182. 查找重复的电子邮箱 | Duplicate Emails
Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...
- LeeCode(Database)-Duplicate Emails
Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...
随机推荐
- Linux PXE + Kickstart 自动装机
大规模装机时,使用无人值守装机便可大大简便人工操作,提高效率. PXE 网络安装 配置双网卡 这里ens33为nat网络,ens37为仅主机网络,配置ens37 [root@localhost ~]# ...
- 元素无法定位问题 NoSuchElementException: Message: no such element: Unable to locate element 解决方法
定位网页上某个按钮时,总是报错元素定位不到,具体如下:NoSuchElementException: Message: no such element: Unable to locate elemen ...
- Selenium库详解
Selenium 自动化测试工具,支持多种浏览器 爬虫中解决JS渲染问题
- pyplot中的一些函数
from matplotlib import pyplot as plt plt.ylabel(‘Grade’) : y轴的名称 plt.xlabel(‘Grade’) : x轴的名称 plt.tit ...
- aliyun-OSS断点续传
阿里云OSS断点续传(Java版本) 在工作中发现开发的某项功能在用户网络环境差的时候部分图片无法显示,通过Review代码之后发现原来是图片上传到了国外的亚马逊服务器上,经过讨论决定将图片上传到国内 ...
- MySQL的delete误操作的快速恢复方法
1. 根据误操作时间定位binlog位置找到数据库的binlog存放位置,当前正在使用的binlog文件里面就有我们要恢复的数据.一般生产环境中的binlog文件都是几百M乃至上G的大小,我们不能逐行 ...
- python--小确幸
#把手机号中间四位隐藏 def change_number(number): hiding_number=number.replace(number[3:7],'*'*4) print(hiding_ ...
- vbs与其他语言进行交互编程(外存传参)
vbs没有自定义排序函数.无需自己造轮子,可以用其他语言来完成这个任务(在传递数据比较简单的情况下,例如只传递数组). 首先用5分钟写一个C++排序的代码.命名为“mysort.cpp”: #incl ...
- 正睿暑期培训day1考试
链接 A 理解一下题意,然后玩几组样例就能发现,实际上就是\(k\)个\(i\)等价于\(1\)个\(i-1\).所以就类似于\(k\)进制进行进位,如果最后\(0\)位上不是\(0\),那么就存在划 ...
- 【转】ServletContext介绍及用法
1.1. 介绍 ServletContext官方叫servlet上下文.服务器会为每一个工程创建一个对象,这个对象就是ServletContext对象.这个对象全局唯一,而且工程内部的所有servl ...