在雇員表中查詢第二高的工資SQL語句助記

2021-09-07 06:20:01 字數 387 閱讀 5231

「在雇員表中查詢第二高的工資的員工記錄」sql語句怎麼寫

這個查詢首先查詢最高工資,然後將它從列表中排除。再查詢最高工資。

非常明顯,第二次返回的是第二高工資。

select top 1 * from employee where salary not int (select max(salary) from emplyee) order by salary desc或者

select top 1 * from(select top 2 * from employee order by salary desc) as t order by salary asc

Sql 查詢工資第二高的記錄

題目要求 給定乙個表employee,有兩個欄位id,salary,要求顯示表中薪水第二的資料.如果沒有第二高,顯示為null mysql select ifnull select distinct salary from employee order by salary desc limit 1 ...

第二高的薪水(SQL查詢語句)

編寫乙個 sql 查詢,獲取employee表中第二高的薪水 salary id salary 1 100 2 200 3 300 例如上述employee表,sql查詢應該返回200作為第二高的薪水。如果不存在第二高的薪水,那麼查詢應返回null。secondhighestsalary 200 答...

sql 實現一張表中查詢雇員的各個季度的銷售總量

建立sales表 create table dbo sales orderid char 10 primary keynot null quantity int null orderdate datetime null employee char 10 null go查詢第一季度的銷售總量 sele...