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.

考察having的使用having的对象是group by中的字段或者是select中使用了聚集函数的字段(当然要对应用了聚集函数的字段取个别名,因为已经不是原先的意义了),如果取了别名可以在having中直接使用该别名如果下面的ECount这个别名,如果没有取那么要把select中的聚集函数表达式再写一次。不过以前用SQLServer的时候好像不能直接用别名,记不清了。

# Write your MySQL query statement below
select Email from (select Email, count(*) as ECount from Person group by Email having ECount > 1) T

LeetCode DB: Duplicate Emails的更多相关文章

  1. LeetCode DB : Delete Duplicate Emails

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

  2. LeetCode Database: Delete Duplicate Emails

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

  3. LeetCode 196. Delete Duplicate Emails (删除重复的电子邮箱)

    题目标签: 题目给了我们一个 email 的表格,让我们删除重复的. 建立Person p1,Person p2,当email 相同时,而且 p1 id 要大于 p2 id 时候,删除这一行. Jav ...

  4. leetcode 196. Delete Duplicate Emails 配合查询的delete

    https://leetcode.com/problems/delete-duplicate-emails/description/ 题意要对原来的数据表进行删除,不删除不行,它每次只输出原来那个表. ...

  5. leetcode 196. Delete Duplicate Emails

    # 慢,内连接delete p1 from Person p1, Person p2 where p1.Email=p2.Email and p1.Id>p2.Id delete from Pe ...

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

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

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

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

  8. LeetCode - Duplicate Emails

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

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

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

随机推荐

  1. WCF:初识

    结构: using System.ServiceModel; namespace MyServices { [ServiceContract] public interface IHomeServic ...

  2. ajax请求报语法错误

    今天改代码修正完一个ajax请求后,调试发现出错进error方法,查看错误信息报语法错误,具体是调用parseJSON方法时出错,因为我是用json方式传递的参数,所以第一时间查看data参数是否正确 ...

  3. Vue2.5开发去哪儿网App 第四章笔记 下

    1.解决非父子组件之间的传值问题 非父子组件传值(Bus/总线/发布订阅模式/观察者模式) 给 Vue类上挂在一个属性,然后创建vue实例时,实例就拥有了这个属性 Vue.prototype.bus ...

  4. Python 百度ai身份证接口案例

    调用百度Ai 完成一个学生信息录入的网页小案例 添加图片,身份证信息对号入座 官方文档中心:https://ai.baidu.com/docs#/OCR-API/7e4792c7 utils.py # ...

  5. 10 Tips for Optimizing Your Website’s Speed

    转自:http://sixrevisions.com/web-development/site-speed-performance/ Web page speed and performance is ...

  6. C语言写了一个socket client端,适合windows和linux,用GCC编译运行通过

    ////////////////////////////////////////////////////////////////////////////////* gcc -Wall -o c1 c1 ...

  7. vector源码1(参考STL源码--侯捷):源码

    vector源码1(参考STL源码--侯捷) vector源码2(参考STL源码--侯捷) vector源码(参考STL源码--侯捷)-----空间分配导致迭代器失效 vector源码3(参考STL源 ...

  8. js中编写velocity逻辑

    <script type="text/javascript"> $(function(){ #foreach( $var in $entity.showConfigs ...

  9. VS2013编译的exe独立运行在XP中方案

    转载知乎 现在,我们深入探讨一下:<如何使用VS 2013发布一个可以在Windows XP中独立运行的可执行文件>. 这个问题是比较常见且容易造成初学者困惑的,作为曾经撞了无数次南墙的初 ...

  10. ASP.NET Core 1.0 中 EntityFramework 与 PostgreSQL 的使用

    https://docs.efproject.net/en/latest/providers/npgsql/index.html 前面在CentOS6.7环境下配置好了PostgreSQL, 就顺便试 ...