top of page

Leetcode 177Nth Highest Salary - Medium

  • crystal0108wong
  • Jun 1, 2017
  • 1 min read

Description

Write a SQL query to get the nth highest salary from the Employee table. For example, given the above Employee table, the nth highest salary where n = 2 is 200. If there is no nth highest salary, then the query should return null. [Read Full Description Here]

Solution

Thought Process

1. Sort the distinct salary in the table;

2. Find the Nth value in those salaries.

Keys

1. Use Limit M, N, which can be considered as the combination of limit and offset function. Here it means get N values starting from the M position.

Comments


Featured Posts
Tag Cloud
Category

Crystal Wang @ 2017

bottom of page