sql leetcode -Duplicate Emails

第一种解法:
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的更多相关文章
- [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. # ...
- LeetCode——Duplicate Emails(使用group by以及having解决分组统计结果)
Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...
- [LeetCode] Delete Duplicate Emails 删除重复邮箱
Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...
- [SQL]LeetCode182. 查找重复的电子邮箱 | Duplicate Emails
Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...
- 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】182. 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 ...
随机推荐
- hdu 3374 String Problem(kmp+最小表示法)
Problem Description Give you a string with length N, you can generate N strings by left shifts. For ...
- 基于配置文件的redis的主从复制
redis中主从复制有很多种配置方法: 1. 使用配置文件即为redis.conf来配置 在随从redis中配置 # slaveof {masterHost} {MastePort} slaveof ...
- Python中何时使用断言 assert
使用断言的最佳时机偶尔会被提起,通常是因为有人误用,因此我觉得有必要写一篇文章来阐述一下什么时候应该用断言,为什么应该用,什么时候不该用. 对那些没有意识到用断言的最佳时机的人来说,Python的断言 ...
- java ee Concurrency 并发编程
https://www.javacodegeeks.com/2014/07/java-ee-concurrency-api-tutorial.html This is a sample chapter ...
- WebService学习总结(一)——WebService的相关概念
一.序言 大家或多或少都听过 WebService(Web服务),有一段时间很多计算机期刊.书籍和网站都大肆的提及和宣传WebService技术,其中不乏很多吹嘘和做广告的成 分.但是不得不承认的是W ...
- 洛谷P1080 国王游戏
两个难点. 怎么想到的贪心? 首先确定算法: 显然不是数据结构题.转成图论也不太可能. 考虑DP:f[i][j]表示前i个人取j状态的最小最大值......2^1000,直接放弃. 因为出现了“最大值 ...
- css之文本两端对齐
在进行网页设计时,我们经常会看到这样的样式:文本两端对齐. css为我们提供了一个属性可以实现这样的效果:text-align: justify.不过这个只能用来设置多行文本(除最后一行).如果只有单 ...
- 1. github配置
1. 安装:官网傻瓜式安装 2.密钥的生成:为了不让不想干的人提交代码,所以需要一个密钥 执行这个命令 : ssh-keygen -t rsa -C "邮箱地址" 然后一直回车键回 ...
- linux 进程创建clone、fork与vfork
目录: 1.clone.fork与vfork介绍 2.fork说明 3.vfork说明 4.clone说明5.fork,vfork,clone的区别 内容: 1.clone.fork与vfork介绍 ...
- 利用/dev/urandom文件创建随机数
1:/dev/urandom和/dev/random是什么 这两个文件记录Linux下的熵池,所谓熵池就是当前系统下的环境噪音,描述了一个系统的混乱程度,环境噪音由这几个方面组成,如内存的使用,文件的 ...