1. 程式人生 > >Leetcode176. Second Highest Salary(MYSQL limit,offset 區別)

Leetcode176. Second Highest Salary(MYSQL limit,offset 區別)

原題
Write a SQL query to get the second highest salary from the Employee table.

+----+--------+
| Id | Salary |
+----+--------+
| 1  | 100    |
| 2  | 200    |
| 3  | 300    |
+----+--------+

For example, given the above Employee table, the second highest salary is 200. If there is no second highest salary, then the query should return null.
思路
從表中選出第二大的數,如果沒有的話,則返回null
在寫SQL語句之前,學習到知識點 Mysql limit offset用法
程式碼

select (select distinct Salary from Employee order by Salary Desc limit 1 ,1)  as SecondHighestSalary 

這裡limit1,1的意思是從第一行開始選,選出第2(1+1)行的數;
或是是
語句1、select * from student limit 9,4 limit後面是從第9條開始讀,讀取4條資訊。
語句2、slect * from student limit 4 offset 9 limit後面跟的是4條資料,offset後面是從第9條開始讀取
語句1和2均返回表student的第10、11、12、13行

注意如果只寫

select distinct Salary from Employee order by Salary Desc limit 1 ,1

這樣子,他就會返回空[],不能返回null,所以有重新添加了一個select語句

相關推薦

Leetcode176. Second Highest SalaryMYSQL limit,offset 區別

原題 Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | Salary | +----+--------+

Second Highest Salary選擇第二高的工資

要求: For example, given the above Employee table, the query should return 200 as the second highest

leetcode176---Second Highest Salary

一、問題描述: Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | Salary | +----+-----

176. Second Highest SalaryLeetcode)

文章出處:http://www.cnblogs.com/grandyang/p/5348961.html Write a SQL query to get the second highest salary from the Employee table. +----+

【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

176. Second Highest Salary SQL查詢語句中的 limit offset

題目: Write a SQL query to get the second highest salary from the Employee table Id | Salary ---|--- 1 | 100 2 | 200 3 | 300 For example, given the ab

176. Second Highest Salary(Easy)

tco targe query rip con -s second count rom Source of the question Write a SQL query to get the second highest salary from the Employee t

176. Second Highest Salary

max color class statement select mysql ble clas cond Write a SQL query to get the second highest salary from the Employee table. +----+-

找第二大的數SQL-Second Highest Salary

des rom tin .com begin get pre sql 最大 1: 找小於最大的最大的 select max(Salary) from Employee where Salary<(select MAX(Salary) from Employe

sql leetcode 176. Second Highest Salary

Write a SQL query to get the second highest salary from the Employeetable. +----+--------+ | Id | Salary | +----+--------+ | 1 | 100 | | 2

LeetCode-第二高的薪水(second-highest-salary)

第二高的薪水 難度 簡單 更多LeetCode答案歡迎大家關注Github: https://github.com/lxyer/LeetCodeAnswer 編寫一個 SQL 查詢,獲取 Employee 表中第二高的薪水(Salary) 。 +----+---

leetcode 2--Second Highest Salary

https://leetcode.com/problems/second-highest-salary/description/ Write a SQL query to get the second highest salary from the Employee table. +—

176.Second Highest Salary

Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | Salary | +----+--------+ | 1 | 100

LeetCode Second Highest Salary

Problem Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | Salary | +----

[LeetCode] Second Highest Salary 第二高薪水

Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | Salary | +----+--------+ | 1 | 100 | | 2 | 2

Second Highest Salary

Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | Salary | +----+--------+ | 1 | 100

【LeetCode】Second Highest Salary && Nth Highest Salary

Total Accepted: 1030 Total Submissions: 4309 My Submissions Question Solution Write a SQL query to get the second highest salary from th

LeetCode-Algorithms #002 Add Two Numbers, Database #176 Second Highest Salary

LeetCode-Algorithms #002 Add Two Numbers 給定兩個非空的以連結串列結構表示的非負整數, 這個結構長這樣: 1 public class ListNode { 2 int val; 3 ListNode next; 4 ListNode(int

leetcode 176. Second Highest Salary

Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | Salary | +----+--------+ | 1 | 100 | | 2 | 200

[理解leetcode解法]176. Second Highest Salary

176. Second Highest Salary #題目: Write a SQL query to get the second highest salary from theEmploy