第一种解法:

select distinct p1.Email as Email from Person p1, Person p2 where p1.Email=p2.Email and p1.Id>p2.id;

  第二种解法:

select Email from Person group by Email having count(Email)>1;

  sql 中有一系列 聚合函数: sum, count, max, avg, 这些函数作用域多条记录上

select sum(population) from b_table;

而通过group by 子句, 可以让sum和 count 这些函数对于属于一组的数据起作用。 计算population,可以指定region

select region, SUM(population),SUM(area)
from b_table
group by region

  having 子句可以筛选成组后的数据,where子句在聚合前筛选记录, 也就是作用域group by ,having子句之前,而having 子句对聚合后的记录进行筛选:

select region, sum(population),sum(area)
from b_table
group by region
having sum(population)>100000

  不能使用where来筛选超过100000的地区,因为表汇总不存在这样的记录。。。

sql leetcode -Duplicate Emails的更多相关文章

  1. [LeetCode] Duplicate Emails 重复的邮箱

    Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...

  2. LeetCode - Duplicate Emails

    Description:Write a SQL query to find all duplicate emails in a table named Person. 找出表中重复的Email. # ...

  3. LeetCode——Duplicate Emails(使用group by以及having解决分组统计结果)

    Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...

  4. [LeetCode] Delete Duplicate Emails 删除重复邮箱

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  5. [SQL]LeetCode182. 查找重复的电子邮箱 | Duplicate Emails

    Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...

  6. Leetcode 182. Duplicate Emails

    Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...

  7. LeetCode DB: Duplicate Emails

    Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...

  8. 【SQL】182. Duplicate Emails

    Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...

  9. LeeCode(Database)-Duplicate Emails

    Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...

随机推荐

  1. CAN总线要点

    前言 CAN总线的应用在现在看来越来越广泛,我厂设备从最初的ARM9与ARM7平台.期间升级过度到CortexA8与Cortex M3平台,再到现在的Cortex M4平台,围绕CAN进行了一系列产品 ...

  2. Java复习总结——详细理解Java反射机制

    反射是什么 反射的作用用一句简单的话来讲就是可以对代码进行操作的代码,这个特性经常在被用于创建JavaBean中,通常造轮子的人会用到这个特性,而应用程序员用到这个特性的场景则较少. 能够分析类能力的 ...

  3. wildfly 10上使用最新的 Hibernate ORM OGM

    ORM是关系型数据库连接:ogm是No sql数据库连接,Mongo, redis等. 1,下载ogm zip包,解压到wildfly_home\modules\system\layers\base, ...

  4. 洛谷P2831 愤怒的小鸟 + 篮球比赛1 2

    这三道题一起做,有一点心得吧. 愤怒的小鸟,一眼看上去是爆搜,但是实现起来有困难(我打了0分出来). 还有一种解法是状压DP. 抛物线一共只有那么多条,我们枚举抛物线(枚举两个点),这样就能够预处理出 ...

  5. 测试利器 Postman

    一.安装 官网:https://www.getpostman.com/ Postman是一个Chrome的一个插件工具,我们可以通过Chrome的应用商店进行进行搜索并安装,安装完成会在桌面上显示一个 ...

  6. windows 文件夹下所有文件名称

    dir dir /b 没有其它信息 dir /b >>xxx.txt 保存到txt

  7. 2019_01_16 sem_init

    sem_init() #include <semaphore.h> int sem_init(sem_t *sem, int pshared, unsigned int value); S ...

  8. java的线程

    public class Test1 extends Thread{ public void run(){ // } } public class Test2 immplement Runnable{ ...

  9. Tomcat 用 startup.bat 启动时,加载信息之后又关闭服务器(差不多一闪而过)问题

    Tomcat 用 startup.bat 启动时,加载信息之后又关闭服务器(差不多一闪而过)问题 以前是正常的,后来在 server.xml 文件的 <Host> </Host> ...

  10. php中函数里面使用函数外面的变量

    一定要在函数里面声明为全局变量!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!(不然会有问题,还是不报错的那种)