LeetCode - Department Highest Salary
题目大概的意思是选出每个Department里工资最高的人的信息并组成相应的表信息
有几个值得注意的地方:1)使用group by语句时,前面的select语句后面的内容只能有两种情况一种是group by后面的属性,另一种是聚集函数。
2)在选取最大Salary时必须使用e1.Salary=e2.Salary and e1.DepartmentId=e2.DepartmentId两个条件,要不然会有重复。
基于这些考虑可以使用派生表查询来找出最大Salary,然后与Department表做自然连接。(最后的升序还是降序无所谓)
select dep.Name as Department, pans.Name as Employee,
pans.Salary as Salary
from Department dep, (
select e1.* from
Employee e1, (select DepartmentId, max(Salary) as Salary
from Employee group by DepartmentId) e2
where e1.Salary=e2.Salary and e1.DepartmentId=e2.DepartmentId
) pans
where dep.Id=pans.DepartmentId
order by pans.Salary desc;
转载于:https://www.cnblogs.com/wxisme/p/4442855.html
LeetCode - Department Highest Salary相关推荐
- 【leetcode Database】184. Department Highest Salary
题目: The Employee table holds all employees. Every employee has an Id, a salary, and there is also a ...
- Second Highest Salary --leetCode
2019独角兽企业重金招聘Python工程师标准>>> Write a SQL query to get the second highest salary from the Emp ...
- 176. Second Highest Salary(必看)
考察limit offset,ifnull, 记得distinct ① selete * from testtable limit 2,1; ② selete * from testtable lim ...
- 177. Nth Highest Salary
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT BEGIN DECLARE M INT; SET M=N-1;RETURN (# Writ ...
- 大二数据库实验-MySQL语句(Employee、Department、Salary)
实验所用到的的几张表: 显示Employee表中姓王的记录. 显示salary 表中InCome大于2000的数据. 显示salary 表中InCome在2500到3000之间的数据. 显示Emplo ...
- LeetCode 从零单刷个人笔记整理(持续更新)
更新至2020.2.23 github:https://github.com/ChopinXBP/LeetCode-Babel 本人博客用于个人对知识点的记录和巩固. 用几乎所有可行的方法进行了实现和 ...
- LeetCode All in One 题目讲解汇总(持续更新中...)
原文地址:https://www.cnblogs.com/grandyang/p/4606334.html 终于将LeetCode的大部分题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开 ...
- leetcode 数据库题目全部题解
来源链接:https://leetcode-cn.com/circle/article/vGr1Mc/ 对数据库专题下每道题目,包括会员题目,都做了详细的题解. 题解内容通常有这么几个部分,题目简述. ...
- 【sql】leetcode习题 (共 42 题)
[175]Combine Two Tables (2018年11月23日,开始集中review基础) Table: Person +-------------+---------+ | Column ...
最新文章
- 目标识别——SIFT算法
- 一张图看懂图像识别算法发展历史
- CentOS 6.3(x86_64)下安装Oracle 10g R2
- 【Android 逆向】GDA 逆向工具安装 ( GDA 下载 | GDA 简介 | 运行 GDA 分析 APK 文件 )
- 用Tableau画圆形网络关系图
- python画圆形螺旋线_这个Python项目,一秒生成可爱像素风图片
- 用正则表达式捕获标识符——随便说
- 转.h和.cpp文件的区别
- 经验:Windows To Go准备工作
- 使用PostgREST的RestAPI操作之相关软件生态系统
- 深度学习论文阅读进阶路径图
- Scrapy爬虫报错AttributeError: ‘NoneType‘ object has no attribute ‘write‘
- Atitit 界面接口技术 cli gui nui cui管理 attilax总结 1. NUI	1 1.1. 问:什么是“自然用户界面”?	1 2. Cli到gui到nui CUI	2 2.1.
- 用C/C++自己写一个宋词生成器,气质一下子就上来了呀
- mysql 根据英文首字母来查询汉字
- CA证书下载以及导出公私钥教程
- 海洋cms模板免费下载
- 学编程难吗?多久能入门?
- 2023凉陌ChatGPT付费创作系统V4.6+功能强大/有后台
- 大数据的应用是什么?有三大关键点