1. 程式人生 > 其它 >顯示hive列名與不顯示錶名

顯示hive列名與不顯示錶名

技術標籤:資料庫演算法

SQL架構

Create table If Not Exists Employee (Id int, 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')

編寫一個 SQL 查詢,獲取 Employee表中第二高的薪水(Salary)。

+----+--------+

| Id | Salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+
例如上述Employee表,SQL查詢應該返回200 作為第二高的薪水。如果不存在第二高的薪水,那麼查詢應返回 null。

+---------------------+
| SecondHighestSalary |
+---------------------+
| 200 |
+---------------------+

SQL語句

# Write your MySQL query statement below
select (select distinct salary from Employee order by salary desc limit 1,1) as SecondHighestSalary 

來源:力扣(LeetCode)
連結:https://leetcode-cn.com/problems/second-highest-salary
著作權歸領釦網路所有。商業轉載請聯絡官方授權,非商業轉載請註明出處。