第一种解法:

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. hdu 2159 FATE (二维完全背包)

    Problem Description 最近xhd正在玩一款叫做FATE的游戏,为了得到极品装备,xhd在不停的杀怪做任务.久而久之xhd开始对杀怪产生的厌恶感,但又不得不通过杀怪来升完这最后一级.现 ...

  2. spring activemq 整合

    创建maven项目 项目目录结构为 首先配置相关maven依赖 <!-- 版本管理 --> <properties> <springframework>4.1.8. ...

  3. 解题:HAOI2018 苹果树

    题面 统计贡献,每个大小为i的子树贡献就是$i(n-i)$,然后子树里又有$i!$种:同时这个子树的根不确定,再枚举这个根是$r$个放的,又有了$r!$种.子树内选点的方式因为子树的根被钦定了顺序所以 ...

  4. 1145. Hashing - Average Search Time

      The task of this problem is simple: insert a sequence of distinct positive integers into a hash ta ...

  5. 利用sqlalchemy读取数据库 和pandas的Dataframe对象 互相生成

    #导入pandas import pandas as pd import numpy as np #导入SqlAlchemy from sqlalchemy import create_engine ...

  6. 数位DP入门题

    站点一览: hdu 2089"不要62" hdu 4734"F(X)" poj 3252"Round Numbers" hdu 3709&q ...

  7. MYSQL Innodb逻辑存储结构

    转载于网络 这几天在读<MySQL技术内幕 InnoDB存储引擎>,对 Innodb逻辑存储结构有了些了解,顺便也记录一下: 从InnoDB存储引擎的逻辑存储结构看,所有数据都被逻辑地存放 ...

  8. qml: 打包 和 发布

    Qt 提供了打包工具windeployqt, 利用该工具可以很方便的解决qt的依赖问题(注:通过实际验证,发现该工具只能解决大部分的依赖问题,不知道是不是本人 没有正确的使用的问题). qt源码编译r ...

  9. python如何直接控制鼠标键盘

    一.简介 我们知道在windows下输入:win + r,会弹出下面的窗口,而在下面的窗口出现后我们接着按下esc键,下面的窗口会消失 现在设想我们想在python代码里控制键盘,想通过运行代码-&g ...

  10. flask form表单验证

    新建forms.py文件 #!/usr/bin/env python #-*-coding:utf--*- #导入模块 from flask_wtf import FlaskForm #FlaskFo ...