Employee表存储员工姓名、员工所在公寓、员工工资

Department表存储公寓id

评选出各个公寓的工资前三名的员工。

遇到的问题如下:

  • limit,in等语句不能用在嵌套select语句中,多封装一层就可以了
  • select子句如何访问外部的关系表,虽然可以直接访问外面第一层的,但是无法访问外面第二层的
select dep.name as Department,
who.name as Employee,
who.salary as Salary
from
department as dep ,employee as who
where dep.id=who.departmentid
and 2>=( select count(1) from (
select distinct salary,departmentid from employee
)as dep_salary
where salary>who.salary and dep_salary.departmentid=dep.id
)
order by Salary desc;

leetcode185 Department Top Three Salaries的更多相关文章

  1. [SQL]LeetCode185. 部门工资前三高的员工 | Department Top Three Salaries

    SQL 架构 Create table If Not Exists Employee (Id ), Salary int, DepartmentId int) Create table If Not ...

  2. [LeetCode] Department Top Three Salaries 系里前三高薪水

    The Employee table holds all employees. Every employee has an Id, and there is also a column for the ...

  3. LeetCode - 185. Department Top Three Salaries

    The Employee table holds all employees. Every employee has an Id, and there is also a column for the ...

  4. 【SQL】185. Department Top Three Salaries

    The Employee table holds all employees. Every employee has an Id, and there is also a column for the ...

  5. LeetCode——Department Top Three Salaries(巧妙使用子查询)

    The Employee table holds all employees. Every employee has an Id, and there is also a column for the ...

  6. 【leetcode】Department Top Three Salaries

    The Employee table holds all employees. Every employee has an Id, and there is also a column for the ...

  7. 185. Department Top Three Salaries

    问题描述 解决方案 select b.name Department,a.name Employee,a.salary Salary from Employee a,Department b wher ...

  8. [LeetCode]-DataBase-Department Top Three Salaries

    The Employee table holds all employees. Every employee has an Id, and there is also a column for the ...

  9. LeetCode All in One 题目讲解汇总(持续更新中...)

    终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...

随机推荐

  1. MySQL必会的28条经典查询

    MySQL必会的28条经典查询   原创作品.转载请注明出处https://blog.csdn.net/kk123k 表结构及测试数据请看我上一篇文章:学生选修成绩表测试数据 Student(Sno, ...

  2. Hibernate @Entity注解配置说明

    持久化是位于JDBC之上的一个更高层抽象. 持久层将对象映射到数据库.以便在查询.装载.更新或删除对象的时候,无须使用像JDBC那样繁琐的API.EJB的早期版本号中.持久化是EJB平台的一部分.EJ ...

  3. 解决Ubuntu下的Eclipse打开Windows编写的java代码的中文乱码

    其实所有的中文乱码 问题都是编码不同所导致的.这里要想让eclipse能正常显示出汉字,就要修改它的字符编码 步骤如下: 1 ,点击菜单栏中的Window(窗口),选择Preferences(首选项) ...

  4. TCP的TIME_WAIT快速回收与重用

    声明一点: Linux中是无法修改tcp的TIME_WAIT值的,除非重新编译,起码我是没有找到怎么改.值得注意的是,net.ipv4.tcp_fin_timeout这个参数是FIN_WAIT_2的值 ...

  5. go语言基础之二维数组

    1.二维数组 示例: package main //必须有个main包 import "fmt" func main() { //有多少个[]就是多少维 //有多少个[]就用多少个 ...

  6. [Javascript] Prototype 1

    You can add prototype to any object in Jacascript likes Object, Array, String... prototype 有继承的作用,比如 ...

  7. 【Nodejs】使用nimble串行化回调任务

    nodejs的nimble模块可以使我们对回调任务进行串行化,它需要先安装 #npm install nimble 用法也方便,示例代码如下: //========================== ...

  8. 通过HTML5 Visibility API检测页面活动状态

    几年前,我们浏览网页的时候是没有选项卡浏览模式的,每一个网页都会是一个浏览器窗口,如果我没有记错,Win7之前我们都是这样浏览网页的.作为一个程序员,我们经常会同时打开10-15个网页,多的时候超过2 ...

  9. 记dynamic的一个小坑 -- RuntimeBinderException:“object”未包括“xxx”的定义

    创建一个控制台程序和一个类库, 在控制台创建一个匿名对象.然后再在类库中訪问它.代码例如以下: namespace ConsoleApplication1 { class Program { stat ...

  10. Session 共享(StateServer模式)(原创)

    Session 共享要注意两点: 1.必须在同一个域名下 2.StateServer模式是把session保存在同一台服务器上的进程:aspnet_state.exe里面,当然也可以保存在memcac ...