首页 > 其他分享 >leetcode 185

leetcode 185

时间:2023-04-12 15:48:22浏览次数:28  
标签:Salary salary Id Department 185 Employee e1 leetcode

部门工资前三高的所有员工

 

select d.name as Department, e.name as Employee, e.salary as Salary from Employee e left join Department d
on e.departmentId = d.Id

where 2 >= (
    select count(distinct e1.salary) from Employee e1
    where e.salary < e1.salary
    and e.departmentId = e1.departmentId
)

order by Department asc , Salary desc

 

select d.name as Department, e.name as Employee, e.salary as Salary from Employee e left join Department d
on e.departmentId = d.Id

where e.Id in
(
    select e1.Id
    from Employee as e1 left join Employee as e2
    on e1.DepartmentId = e2.DepartmentId and e1.Salary < e2.Salary
    group by e1.Id
    having count(distinct e2.Salary) <= 2
)

order by Department asc , Salary desc

 

==

 

标签:Salary,salary,Id,Department,185,Employee,e1,leetcode
From: https://www.cnblogs.com/carlzhang19/p/17310022.html

相关文章

  • LeetCode #448 找到所有数组中消失的数字
    基本思路为了满足题目要求的不使用额外的存储空间(当然返回的数组除外),并且时间复杂度控制在O(n),最多只能常数级别遍历,因此考虑将原数组视作一个"哈希表"。遍历原数组,将【1,n】上的值域映射到【0,n-】的坐标上,某个数x扫描到一次则将这个数x映射的x-1的坐标处的值加上n。......
  • LeetCode #283 移动零(双指针版本,效率高)
    基本思路思路————双指针初始状态左右指针都指向数组首位元素,然后right指针开始迭代数组,当碰到非0元素则与左指针left所在位置的元素交换。交换完毕后,左指针left则向前移动到下一位置,做好准备迎接下一个非0元素的交换。这种算法效率比之前撰写的“伪双指针”......
  • LeetCode #414 第三大的数
    解题思路数组从大到小排序后,从第2个元素开始遍历,如果与上一个元素不相同,则标志位++,标志位一旦从1加到3(两次)则代表存在第三大的数,即可返回。如若不存在第三大的数,则在遍历结束后,函数末尾返回数组的第一个元素(最大的元素)。标程1classSolution{2public:3intthirdMa......
  • LeetCode #485 最大连续 1 的个数
    解题思路基础题,最后加一个特殊情况处理就好,时间复杂度O(n)代码  classSolution{public:intfindMaxConsecutiveOnes(vector<int>&nums){intcount=0;intMaxcount=0;for(inti=0;i<nums.size();i++){if(nums[i]==1){......
  • #yyds干货盘点# LeetCode面试题:矩阵置零
    1.简述:给定一个 mxn的矩阵,如果一个元素为0,则将其所在行和列的所有元素都设为0。请使用原地算法。 示例1:输入:matrix=[[1,1,1],[1,0,1],[1,1,1]]输出:[[1,0,1],[0,0,0],[1,0,1]]示例2:输入:matrix=[[0,1,2,0],[3,4,5,2],[1,3,1,5]]输出:[[0,0,0,0],[0,4,5,0],[0,3,1,0]]......
  • 4月11日leetcode练习
    设计一个支持push,pop,top操作,并能在常数时间内检索到最小元素的栈。实现MinStack类:MinStack()初始化堆栈对象。voidpush(intval)将元素val推入堆栈。voidpop()删除堆栈顶部的元素。inttop()获取堆栈顶部的元素。intgetMin()获取堆栈中的最小元素。 来源:力扣(Le......
  • leetcode 183
    从不订购的客户 selectc.NameasCustomersfromCustomerscleftjoinOrdersoonc.Id=o.CustomerIdwhereo.CustomerIdisnull selectcustomers.namecustomersfromcustomerswherecustomers.idnotin(selectorders.customeridfromorders) ......
  • leetcode 181
    超过经理收入的员工 selecte1.nameasEmployeefromEmployeee1,Employeee2wheree1.managerId=e2.idande1.salary>e2.salary selecte1.nameasEmployeefromEmployeee1leftjoinEmployeee2one1.managerId=e2.idwheree1.salary>e2.salary......
  • 【LeetCode回溯算法#extra01】集合划分问题【火柴拼正方形、划分k个相等子集、公平发
    火柴拼正方形https://leetcode.cn/problems/matchsticks-to-square/你将得到一个整数数组matchsticks,其中matchsticks[i]是第i个火柴棒的长度。你要用所有的火柴棍拼成一个正方形。你不能折断任何一根火柴棒,但你可以把它们连在一起,而且每根火柴棒必须使用一次。如......
  • [LeetCode] 2390. Removing Stars From a String
    Youaregivenastring s,whichcontainsstars *.Inoneoperation,youcan:Chooseastarin s.Removetheclosest non-star charactertoits left,aswellasremovethestaritself.Return thestringafter all starshavebeenremoved.Note:Thei......