MySql取第二高薪水

2021-10-16 12:58:39 字數 727 閱讀 7040

mysql取第二高薪水

#(1)

select

salary as secondhighestsalary

from employee

order by

salary desc

#limit後面可以跟乙個或倆個引數:

#(1)只有乙個引數時,預設取排序後最上面的一條

#(2)倆個引數時:

#i.第乙個引數代表從第幾條資料開始取,預設從0開始;

#ii.第二個引數代表取多少條資料。

limit 1,1

– limit 1,-1 代表取從第二條到最後

#(2)首先取最大的一條,那麼除去這條後最大的便是第二高的薪水。

select

max(salary) as secondhighestsalary

from employee

where salary not in

(select

max(salary) as salary

from employee)

#(3)limit x offset y 從第x條開始,取y條

select

salary as secondhighestsalary

from employee

order by

salary desc

limit 1

offset 1

第二高薪水

需求 編寫乙個 sql 查詢,獲取employee表中第二高的薪水 salary 例如上述employee表,sql查詢應該返回200作為第二高的薪水。如果不存在第二高的薪水,那麼查詢應返回null。解 select ifnull select distinct salary from employ...

mysql查詢第二高薪水

問題描述 編寫一條sql,查詢應該返回 200 作為第二高的薪水。如果不存在第二高的薪水,那麼查詢應返回 null。表名為employee員工表 解決思路 有資料返回資料,無資料返回null。根據這個要求,我們可以考慮採用mysql的ifnull函式 摘自菜鳥教程 ifnull 函式用於判斷第乙個表...

查詢第二高薪水

表名employee idsaraly 1100 2200 3300 預期結果 secondhighestsalary 200mysql select max salary as secondhighestsalary from select salary from employee where s...