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 ...
随机推荐
- Can DBC文件翻译
1 引言 DBC文件描述单个CAN网络的通信.这个信息足以监测和分析网络并模拟不是物理可用的节点(剩余的总线模拟). DBC文件也可以用来开发电子控制单元的通信软件,该控制单元应该是CAN网络的一部分 ...
- shell中的source和直接执行sh的区别
首先我们知道我们执行shell有这么几种方法 1. sh/bash使用其内置的命令集来执行一些命令,例如如下 sh demo.sh bash demo.sh 2. 使用./或者/$SHELLPATH/ ...
- css border 三角形
当元素的宽高都为0时,只写border,就会发现形成的正方形有4个三角形组成. .triangle { width: 0px; height: 0px; border: 20px solid tran ...
- 当我new class的时候,提示以下错误: Unable to parse template "Class" Error message: This template did not produce a Java class or an interface Error parsing file template: Unable to find resource 'Package Header.j
你肯定修改过class的template模板,改回去就好了 #if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")packag ...
- java练习:质数,匿名内部类创建接口,抽象类派生子类,画圆,字节截取字符串,数字变钱币,五子棋,梭哈
java学习-质数的孤独 正在看质数的孤独,,,于是写了一个练习代码,输出1-100之间的质数 代码比较烂.待完善吧. 这里用到了continue和break,continue指结束当前轮次循环,跳入 ...
- 使用postman测试hystrix
当在浏览器发送多次请求检测hystrix的作用时,我们可以使用postman来自动发送多次请求: 1.将链接保存到一个collection中 2.点击runner 3.设定运行次数
- (数学 尾0的个数) 51nod1003 阶乘后面0的数量
n的阶乘后面有多少个0? 6的阶乘 = 1*2*3*4*5*6 = 720,720后面有1个0. 收起 输入 一个数N(1 <= N <= 10^9) 输出 输出0的数量 输入样例 5 ...
- Error[Pe020]: identifier "FILE" is undefined
Error[Pe020]: identifier "FILE" is undefined 需要添加头文件:#include <stdio.h>
- 根据指定的key,将二维数组的value转换为string,适用于mysql的in查询
function array_unique_join($arr,$param){ $utm_source_arr = array_unique(array_column($arr,$param)); ...
- 新建体(3):dbms_job下新建一个job定期自动执行存储过程
http://blog.csdn.net/thinkscape/article/details/7411012http://java-admin.iteye.com/blog/231159sql窗口执 ...