【LeetCode】176.第二高的薪水
176.第二高的薪水
編寫一個 SQL 查詢語句,獲取Employee
表中第二高的薪水(Salary)。
用到的表和資料SQL:
Create table If Not Exists Employee (Idint, Salary int);
Truncate table Employee;
insert into Employee (Id, Salary) values('1', '100');
insert into Employee (Id, Salary) values('2', '200');
insert into Employee (Id, Salary) values('3', '300');
答案:
此題可以分為兩塊考慮,第一塊是最高的薪水,第二個是比最高薪水小的最高的薪水
select Max(Salary) SecondHighestSalary
from Employee where (select Max(Salary)from Employee) > Salary
寫的比較粗糙,有不理解的可以掃描二維碼加QQ群找我解答。
相關推薦
【Leetcode】176. 第二高的薪水
題目 編寫一個 SQL 查詢,獲取 Employee 表中第二高的薪水(Salary) 。 +----+--------+ | Id | Salary | +----+--------+ | 1 | 100 | | 2 | 200 | | 3
【LeetCode】176.第二高的薪水
176.第二高的薪水編寫一個 SQL 查詢語句,獲取Employee表中第二高的薪水(Salary)。用到的表和資料SQL:Create table If Not Exists Employee (Id
【Leetcode】176. Second Highest Salary (Easy)
1.題目Write a SQL query to get the second highest salary from the Employee table.+----+--------+ | Id | Salary | +----+--------+ | 1 | 100
【Leetcode】Mysql查詢第二高的薪水
編寫一個 SQL 查詢,獲取 Employee 表中第二高的薪水(Salary) 。 +—-+——–+ | Id | Salary | +—-+——–+ | 1 | 100 | | 2
Leetcode 176. 第二高的薪水
編寫一個 SQL 查詢,獲取 Employee 表中第二高的薪水(Salary) 。 +----+--------+ | Id | Salary | +----+--------+ | 1 | 100 | | 2 | 200 | | 3 | 300
LeetCode--176--第二高的薪水
問題描述: 編寫一個 SQL 查詢,獲取 Employee 表中第二高的薪水(Salary) 。 +----+--------+ | Id | Salary | +----+--------+ | 1 | 100 | | 2 | 200 | | 3 | 300 | +----+----
【Leetcode】Mysql查詢第N高的薪水
編寫一個 SQL 查詢,獲取 Employee 表中第 n 高的薪水(Salary)。 +----+--------+ | Id | Salary | +----+--------+ | 1 | 100 | | 2 | 200 | | 3
【LeetCode】177.第N高的薪水
177.第N高的薪水編寫一個 SQL 查詢語句,獲取Employee表中第n高的薪水(Salary)。用到的表和資料SQL:Create table If Not Exists Employee (Id
LeetCode #176第二高的薪水
查詢第二高的資料,思路就是先找到最大值,然後在剩下的資料裡找到比最大值要小的最大值。一開始我的做法是用ifnull函式,但預設值的資料型別會改變薪水的資料型別,ifnull(Salary,null)時遇
【leetcode】177. 第N高的薪水
這題其實和177思想比較接近,排序就行了 程式碼: CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT BEGIN RETURN ( # Write your MySQL query state
LeetCode.176. 第二高的薪水
思路1: 即降序排序後取第二個。這裡難搞的是空值情況。最後使用isnull函式,如果選擇為空,則返回為空。 程式碼1: SELECT ifnull( ( SELECT DISTINCT Salary FROM Employee ORDER BY Sala
176. 第二高的薪水
沒有 The 臨時 pro use 如果 ng-if ifnull highest Write a SQL query to get the second highest salary from the Employee table. +----+--------+ |
[LeetCode] Second Highest Salary 第二高薪水
Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | Salary | +----+--------+ | 1 | 100 | | 2 | 2
leetcode 第二高薪水
直接查詢如果不存在第二高的Salary不會返回值,所以應該用子查詢 select (select distinct Salary from Employee order by Salary des
176.第二高的薪水
解析 select max(Salary) as SecondHighestSalary from Employee where Salary <(select max(Salary) from Employee ) 最大查詢 select max(col
【LeetCode】091. Decode Ways
rom size etc oss following nbsp pan ron ann 題目: A message containing letters from A-Z is being encoded to numbers using the following map
【LeetCode】040. Combination Sum II
log bsp for ont end ati 無法 clas class 題目: Given a collection of candidate numbers (C) and a target number (T), find all unique combinatio
【LeetCode】240. Search a 2D Matrix II
target ott arc rop win mat ive pty his 題目: Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the
【LeetCode】215. Kth Largest Element in an Array
distinct class ted ++ bsp order algo max git 題目: Find the kth largest element in an unsorted array. Note that it is the kth largest eleme
【LeetCode】169. Majority Element
turn end and else pear ive element emp bsp 題目: Given an array of size n, find the majority element. The majority element is the element t