SELECTMAX(Salary)FROMEmployee E1WHERE1=(SELECTCOUNT(DISTINCT(E2.Salary))FROMEmployee E2WHEREE2.Salary>E1.Salary); 参考资料: https://leetcode.com/discuss/47041/very-very-simple-solution https://leetcode.com/discuss/42849/general-solution-not-using-max https://leetcode.com/discuss/21751/simple-...
Runtime: 153ms, faster than 44 % 完成日期:05/22/2019 关键点:MAX, NOT IN # Write your MySQL query statement belowSELECTMax(Salary)AsSecondHighestSalaryFROMEmployeeWHERESalaryNOTIN(SELECTMax(Salary)FROMEmployee); 参考资料:LeetCode Solution LeetCode 题目列表 -LeetCode Questions List...
For example, given the above Employee table, the second highest salary is200. If there is no second highest salary, then the query should returnnull. 大意是选出第二高的Salary。 1 2 3 4 # Write your MySQL query statement below selectmax(Salary)fromEmployee where Salary < (selectmax(Salary...
Can you solve this real interview question? Second Highest Salary - Table: Employee +---+---+ | Column Name | Type | +---+---+ | id | int | | salary | int | +---+---+ id is the primary key (column
SELECTMAX(e1.salary)asSecondHighestSalaryFROMEmployee e1JOINEmployee e2WHEREe1.salary<e2.salary; 2.子查询 子查询方法。用子查询找出最大值,再排除最大值的结果中,求最大值。必须要借助于MAX函数。 selectmax(salary)asSecondHighestSalaryfromEmployeewheresalary!=(selectmax(salary)fromEmployee); ...
题目的意思是,在Employee表中找到第二大的Salary字段,然后以别名“SecondHighestSalary ”的形式输出 解题思路: 本题有两种思路。 一种是找到找到最大值,然后我们取比最大值小一点的最大值。 SQL: SELECTMax(Salary)asSecondHighestSalaryFROMEmployeeWHERESalary<(SELECTMax(Salary)FROMEmployee); ...
解法2. 参考 http://tsuinte.ru/2015/04/05/leetcode-database-176-second-highest-salary 构造一个tmp,从里面选,如果tmp为空则返回null 1# Write your MySQL query statement below2select3if(count(Salary)>=1, Salary,null)asSecondHighestSalary4from(selectdistinctsalaryfromEmployee5orderbySalarydesclimit...
For example, given the above Employee table, the second highest salary is200. If there is no second highest salary, then the query should returnnull. 思路: 如果是选出所有Salary中最大的,语句是: 1 2 selectmax(Salary) fromEmployee (*) ...
【leetcode SQL】Second Highest Salary 原题如下: Write a SQL query to get the second highest salary from theEmployeetable. +---+---+ | Id | Salary | +---+---+ | 1 | 100 | | 2 | 200 | | 3 | 300 | +---+---+ 1...
leetcode 176. Second Highest Salary https://leetcode.com/problems/second-highest-salary/description/ 题目要求输出第二大的成绩。 首先可以想到去重,然后排序,相当于输出第二个成绩。 这个用limit a offset b表示,从第b项开始,选出a个,下标从0开始...