176. Second Highest Salary(SQL)

# Easy

# Write your MySQL query statement below
select distinct
    Salary as SecondHighestSalary
from Employee
    order by Salary desc 
    limit 1 offset 1; 

distinct 不要忘了,仔细读题

limit 表示只取出1个

offset 表示偏移1位,到top2了,这时候取出1个正好是第二大的

desc 表示降序排列,asc 表示升序排列

重命名的语法也要注意,select x as y from tableName

Last updated