1. 程式人生 > >【Leetcode】176. Second Highest Salary (Easy)

【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    |
| 2  | 200    |
| 3  | 300    |
+----+--------+

For example, given the above Employee table, the query should return 200 as the second highest salary. If there is no second highest salary, then the query should return null

.

+---------------------+
| SecondHighestSalary |
+---------------------+
| 200                 |
+---------------------+
翻譯:找到一張表中,第二大的值標記為SecondHighestSalary,如果沒有則返回null。

2.思路

小於最大Salary的最大Salary即為第二大的Salary值

3.演算法

select MAX(Salary) as SecondHighestSalary
from Employee where Salary<(select MAX(Salary) from Employee)


相關推薦

Leetcode176. Second Highest Salary Easy

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

Leetcode482. License Key FormattingEasy

1.題目You are given a license key represented as a string S which consists only alphanumeric character and dashes. The string is separated i

Leetcode196. Delete Duplicate Emails Easy

1.題目Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id.翻

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. +----+

LeetCode184. Department Highest Salary

The Employee table holds all employees. Every employee has an Id, a salary, and there is also a column for the department Id. +----+----

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

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

LeetCode40. Combination Sum IIC++

地址:https://leetcode.com/problems/combination-sum-ii/ 題目: Given a collection of candidate numbers (candidates) and a target number (target), fi

LeetCode29. Divide Two IntegersC++

地址:https://leetcode.com/problems/divide-two-integers/ 題目: Given two integers dividend and divisor, divide two integers without using multiplic

LeetCode73. Set Matrix ZeroesC++

地址:https://leetcode.com/problems/set-matrix-zeroes/ 題目: Given a m m

LeetCode64. Minimum Path SumC++

地址:https://leetcode.com/problems/minimum-path-sum/ 題目: Given a m ∗

LeetCode63. Unique Paths IIC++

地址:https://leetcode.com/problems/unique-paths-ii/ 題目: A robot is located at the top-left corner of a m

LeetCode93. Restore IP AddressesC++

地址:https://leetcode.com/problems/restore-ip-addresses/ 題目: Given a string containing only digits, restore it by returning all possible valid I

LeetCode743. Network Delay TimeC++

題目: There are N network nodes, labelled 1 to N. Given times, a list of travel times as directed edges times[i] = (u, v, w), where

LeetCode754. Reach a NumberC++

題目: You are standing at position 0 on an infinite number line. There is a goal at position target. On each move, you can either go

LeetCode10. Regular Expression MatchingC++

地址:https://leetcode.com/problems/regular-expression-matching/ 題目: Given an input string (s) and a pattern (p), implement regular expression ma

LeetCode5. Longest Palindromic SubstringC++

題目: Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example 1:

LeetCode32. Longest Valid ParenthesesC++

地址:https://leetcode.com/problems/longest-valid-parentheses/ 題目: Given a string containing just the characters '(' and ')', find the length of

LeetCode76. Minimum Window SubstringC++

地址:https://leetcode.com/problems/minimum-window-substring/ 題目: Given a string S and a string T, find the minimum window in S which will contai

LeetCode45. Jump Game IIC++

地址:https://leetcode.com/problems/jump-game-ii/ 題目: Given an array of non-negative integers, you are initially positioned at the first index of

LeetCode696. Count Binary SubstringsC++

地址:https://leetcode.com/problems/count-binary-substrings/ 題目: Give a string s, count the number of non-empty (contiguous) substrings that have