leetcode_sql_3,181,182,183
181. Employees Earning More Than Their Managers
The Employee
table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.
- +----+-------+--------+-----------+
- | Id | Name | Salary | ManagerId |
- +----+-------+--------+-----------+
- | 1 | Joe | 70000 | 3 |
- | 2 | Henry | 80000 | 4 |
- | 3 | Sam | 60000 | NULL |
- | 4 | Max | 90000 | NULL |
- +----+-------+--------+-----------+
Given the Employee
table, write a SQL query that finds out employees who earn more than their managers. For the above table, Joe is the only employee who earns more than his manager.
# Write your MySQL query statement below
SELECT A.Name Employee
FROM Employee A,Employee B
WHERE A.ManagerId=B.Id AND A.Salary >B.Salary;
182. Duplicate Emails
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.
# Write your MySQL query statement below
SELECT Distinct(a.Email)
FROM Person a,Person b
WHERE a.Id<>b.Id and a.Email=b.Email
or
select Email
from Person
group by Email
having count(*) > 1
183. Customers Who Never Order
Suppose that a website contains two tables, the Customers
table and the Orders
table. Write a SQL query to find all customers who never order anything.
Table: Customers
.
- +----+-------+
- | Id | Name |
- +----+-------+
- | 1 | Joe |
- | 2 | Henry |
- | 3 | Sam |
- | 4 | Max |
- +----+-------+
Table: Orders
.
- +----+------------+
- | Id | CustomerId |
- +----+------------+
- | 1 | 3 |
- | 2 | 1 |
- +----+------------+
Using the above tables as example, return the following:
- +-----------+
- | Customers |
- +-----------+
- | Henry |
- | Max |
- +-----------+
SELECT A.Name from Customers A LEFT JOIN Orders B on a.Id = B.CustomerId WHERE b.CustomerId is NULL;
select c.Name from Customers c
where (select count(*) from Orders o where o.customerId=c.id)=0
select c.Name from Customers c
where not exists (select * from Orders o where o.customerId=c.id)
leetcode_sql_3,181,182,183的更多相关文章
- sql_自连接,181,182,196,197
181. Employees Earning More Than Their Managers https://leetcode.com/problems/employees-earning-more ...
- [SQL]3.26--175+176+177+178+180+181+182
175.组合两个表 题目 Code SELECT FirstName, LastName, City, State FROM Person LEFT JOIN Address --由于需要Person ...
- 悼念传奇,约翰询问·纳什和他的妻子艾丽西亚致敬,创建一个传奇,爱数学
约翰·阅读·纳什的传记.我渴望录制通道 我一直相信数字,无论逻辑方程使我们认为.但这种追求一生的后,我问自己:"这是什么逻辑?谁决定的理由?"我的探索让我从物理到形而上,最后到了妄 ...
- 一些随机数据的生成(日期,邮箱,名字,URL,手机号,日期等等)
直接上代码 import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import jav ...
- 【WEB前端】使用百度ECharts,绘制项目质量报表
一.下载ECharts的js库 下载地址:http://echarts.baidu.com/download.html 由于我们对体积无要求,所以我们采用了完整版本,功能齐全,在项目中,我们只需要像普 ...
- 利用Chrome插件向指定页面植入js,劫持 XSS
资源来自:http://www.2cto.com/Article/201307/225986.html 首页 > 安全 > 网站安全 > 正文 利用Chrome插件向指定页面植入js ...
- android复制数据库到SD卡(网上搜集,未经验证)
android中使用sqlite.复制assets下的数据库到SD卡.支持大于1M的文件 如果使用SD卡,需要在AndroidManifest.xml中设置权限 <uses-permission ...
- android弧形进度条,有详细注释的,比较简单
Java code? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ...
- Python编写的Linux网络设置脚本,Debian Wheezy上测试通过
hon编写的Linux网络设置脚本,Debian Wheezy上测试通过 阿里百川梦想创业大赛,500万创投寻找最赞的APP 技术细节参见Linux网络设置高级指南 注意事项参见程序注释 ...
随机推荐
- display:inline-block; 去除间隙的方法 总结:
个人常用: 如: <ul> <li><a href="#" >实时数据</a></li> <li><a ...
- Python3.x:定时自动发送邮件
定时自动发送邮件 一.简述 python发邮件需要掌握两个模块的用法,smtplib和email,这俩模块是python自带的,只需import即可使用.smtplib模块主要负责发送邮件,email ...
- 解决Vim插入模式下backspace按键无法删除字符的问题【转】
本文转载自:https://blog.csdn.net/zxy987872674/article/details/64124959 最近使用某个服务器编辑文件时,快捷键i进入插入模式后,下方不出现in ...
- Metasploit 内网渗透篇
0x01 reverse the shell File 通常做法是使用msfpayload生成一个backdoor.exe然后上传到目标机器执行.本地监听即可获得meterpreter shell. ...
- php上传文件后无法移动到指定目录的解决
从浏览器访问而触发PHP脚本运行的用户是 apache 用户 无法移动文件的原因主要是目标目录没有写入权限 1.将目标目录权限设置为 777 #chmod 777 tar_dir 2.将目标目录用户和 ...
- 洛谷P4311 士兵占领
题目描述 有一个M * N的棋盘,有的格子是障碍.现在你要选择一些格子来放置一些士兵,一个格子里最多可以放置一个士兵,障碍格里不能放置士兵.我们称这些士兵占领了整个棋盘当满足第i行至少放置了Li个士兵 ...
- [TJOI2010]打扫房间
题目描述 学校新建了一批宿舍,值日生小A要把所有的空房间都打扫一遍.这些宿舍的布局很奇怪,整个建筑物里所有的房间组成一个N * M的矩阵,每个房间的东南西北四面墙上都有一个门通向隔壁房间.另外有些房间 ...
- infa dos命令
informatica8.6用dos命令执行作业的命令: pmcmd startworkflow -sv integration -d Domain_BlueBreezeq -u Administra ...
- C语言之非常简单的几道题
C语言之非常简单的几道题(还是写写),比较简单吧,主要有几道题的数据类型(如,第三题)和语句顺序(如,第二题)需要注意一小下下. 1. 求表达式S=1*2*3……*N的值大于150时,最小的N的值 / ...
- Pandas分组(GroupBy)
任何分组(groupby)操作都涉及原始对象的以下操作之一.它们是 - 分割对象 应用一个函数 结合的结果 在许多情况下,我们将数据分成多个集合,并在每个子集上应用一些函数.在应用函数中,可以执行以下 ...