leetcode数据库sql之Department Top Three Salaries

leetcode原文引用:

How would you print just the 10th line of a file?

For example, assume that file.txt has the following content:

Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10

Your script should output the tenth line, which is:

Line 10

我的sql语句如下:

SELECT  d.name as department, e.name,e.salary
FROM Employee e JOIN Department d ON e.departmentid = d.id
and
    (SELECT   COUNT(DISTINCT (salary))
     FROM
            Employee
     WHERE
            departmentid = e.departmentid
     AND    salary > e.salary
     ) < 3
ORDER BY d.id ASC , e.salary DESC

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-07 02:07:59

leetcode数据库sql之Department Top Three Salaries的相关文章

[LeetCode][SQL]Department Top Three Salaries

Department Top Three Salaries The Employee table holds all employees. Every employee has an Id, and there is also a column for the department Id. +----+-------+--------+--------------+ | Id | Name | Salary | DepartmentId | +----+-------+--------+----

LeetCode Department Top Three Salaries

The Employee table holds all employees. Every employee has an Id, and there is also a column for the department Id. +----+-------+--------+--------------+ | Id | Name | Salary | DepartmentId | +----+-------+--------+--------------+ | 1 | Joe | 70000

【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 department Id. +----+-------+--------+--------------+ | Id | Name | Salary | DepartmentId | +----+-------+--------+--------------+ | 1 | Joe | 70000

185. Department Top Three Salaries (Hard)

Source: https://leetcode.com/problems/department-top-three-salaries/#/description Description: The Employee table holds all employees. Every employee has an Id, and there is also a column for the department Id. +----+-------+--------+--------------+

leetcode数据库sql之Delete Duplicate Emails

leetcode原文引用: Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id. +----+------------------+ | Id | Email | +----+------------------+ | 1 | [email protected] | | 2 | [em

leetcode数据库sql之Rising Temperature

leetcode原文引用: Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to its previous (yesterday's) dates. +---------+------------+------------------+ | Id(INT) | Date(DATE) | Temperature(INT) | +---------+---

leetcode185 部门工资前三高的所有员工 Department Top Three Salaries

Employee 表包含所有员工信息,每个员工有对应的 Id,此外还有一列部门 Id. 创建表和数据: Create table If Not Exists Employee (Idint, Name varchar(255), Salary int, DepartmentId int); Create table If Not Exists Department (Idint, Name varchar(255)); Truncate table Employee; insert into E

【转】数据库SQL优化大总结之 百万级数据库优化方案

原帖地址:http://www.cnblogs.com/yunfeifei/p/3850440.html#undefined 1.对查询进行优化,要尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索引而进行全表扫描,如: select id from t where num is null 最好不要给数据库留NULL,尽可能的使用 NOT NULL填充数据库. 备注.描

数据库SQL优化大总结之 百万级数据库优化方案(转)

出处:http://www.cnblogs.com/yunfeifei/p/3850440.htm 网上关于SQL优化的教程很多,但是比较杂乱.近日有空整理了一下,写出来跟大家分享一下,其中有错误和不足的地方,还请大家纠正补充.这篇文章我花费了大量的时间查找资料.修改.排版,希望大家阅读之后,感觉好的话推荐给更多的人,让更多的人看到.纠正以及补充. 1.对查询进行优化,要尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对