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 ...
随机推荐
- 牛客小白月赛12J(序列自动机)
题目链接:https://ac.nowcoder.com/acm/contest/392/J 题目大意:给一个字符串s,然后在给出n个其他的字符串,判断每个字符串是否为s的子序列. 例: 输入: no ...
- JS时间戳转换成时间格式
TimeNow: function (val) { var date = new Date(val); var Y = date.getFullYear(); var m = date.getMont ...
- poj2054 Color a Tree
神题.这题是巨毒瘤... 自己写真可谓是: 排空驭气奔如电,上天入地求之遍 上穷碧落下黄泉,两处茫茫皆不见 由于我们知道:不是树形时,不停选值最大的节点可以得到最小代价. 那么我们就能想出一个错误的贪 ...
- pandas 连接数据库直接查表建立dataframe。loc,sort_values数据清洗操作
#导入pandas import pandas as pd import numpy as np #导入SqlAlchemy from sqlalchemy import create_engine ...
- 【洛谷P1060 开心的金明】
题目描述 金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间他自己专用的很宽敞的房间.更让他高兴的是,妈妈昨天对他说:“你的房间需要购买哪些物品,怎么布置,你说了算,只要不超过NNN元钱就行”. ...
- Could not install the app on the device, read the error above for details. Make sure you have an Android emulator running or a device connected and have set up your Android development environment:
Administrator@DESKTOP-EHCTIOR MINGW64 /d/react-native-eyepetizer (master) $ react-native run-android ...
- 交叉编译jpeglib遇到的问题
由于要在开发板中加载libjpeg,不能使用gcc编译的库文件给以使用,需要自己配置使用另外的编译器编译该库文件. /usr/bin/ld: .libs/jaricom.o: Relocations ...
- 2018.11.26 QLU新生赛部分题解
问题 L: 寄蒜几盒? 题目描述 现在有一个圆圈,圆圈上有若干个点,请判断能否在若干个点中选择三个点两两相连组成一个等边三角形? 这若干个点在圆圈上按顺时针顺序分布. 如果可以的话输出"Ye ...
- 在gitlab新建空项目,将本地的git仓库的内容上传
gitlab新建了这个项目. 按照官网的步骤上传代码 一:将本地代码上传到本地仓库 1.进入项目文件夹 git init 2.项目代码添加到本地git git add . 3.提交到stage区域 g ...
- selenium-网站demo学习-test Design-优化自动化代码
看selenium的网站的文档,里面的自动化用例设计有一些小点很靠谱.学了很多,可以用作优化自己的代码. 1.测试类型: Testing Static Content Testing Links Fu ...