{ "data": { "question": { "questionId": "177", "questionFrontendId": "177", "boundTopicId": null, "title": "Nth Highest Salary", "titleSlug": "nth-highest-salary", "content": "

Table: Employee

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| id          | int  |\n| salary      | int  |\n+-------------+------+\nid is the primary key column for this table.\nEach row of this table contains information about the salary of an employee.\n
\n\n

 

\n\n

Write an SQL query to report the nth highest salary from the Employee table. If there is no nth highest salary, the query should report null.

\n\n

The query result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nEmployee table:\n+----+--------+\n| id | salary |\n+----+--------+\n| 1  | 100    |\n| 2  | 200    |\n| 3  | 300    |\n+----+--------+\nn = 2\nOutput: \n+------------------------+\n| getNthHighestSalary(2) |\n+------------------------+\n| 200                    |\n+------------------------+\n
\n\n

Example 2:

\n\n
\nInput: \nEmployee table:\n+----+--------+\n| id | salary |\n+----+--------+\n| 1  | 100    |\n+----+--------+\nn = 2\nOutput: \n+------------------------+\n| getNthHighestSalary(2) |\n+------------------------+\n| null                   |\n+------------------------+\n
\n", "translatedTitle": null, "translatedContent": null, "isPaidOnly": false, "difficulty": "Medium", "likes": 1003, "dislikes": 637, "isLiked": null, "similarQuestions": "[{\"title\": \"The Number of Users That Are Eligible for Discount\", \"titleSlug\": \"the-number-of-users-that-are-eligible-for-discount\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]", "exampleTestcases": "{\"headers\": {\"Employee\": [\"id\", \"salary\"]}, \"argument\": 2, \"rows\": {\"Employee\": [[1, 100], [2, 200], [3, 300]]}}\n{\"headers\": {\"Employee\": [\"id\", \"salary\"]}, \"argument\": 2, \"rows\": {\"Employee\": [[1, 100]]}}", "categoryTitle": "Database", "contributors": [], "topicTags": [ { "name": "Database", "slug": "database", "translatedName": null, "__typename": "TopicTagNode" } ], "companyTagStats": null, "codeSnippets": [ { "lang": "MySQL", "langSlug": "mysql", "code": "CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT\nBEGIN\n RETURN (\n # Write your MySQL query statement below.\n \n );\nEND", "__typename": "CodeSnippetNode" }, { "lang": "MS SQL Server", "langSlug": "mssql", "code": "CREATE FUNCTION getNthHighestSalary(@N INT) RETURNS INT AS\nBEGIN\n RETURN (\n /* Write your T-SQL query statement below. */\n \n );\nEND", "__typename": "CodeSnippetNode" }, { "lang": "Oracle", "langSlug": "oraclesql", "code": "CREATE FUNCTION getNthHighestSalary(N IN NUMBER) RETURN NUMBER IS\nresult NUMBER;\nBEGIN\n /* Write your PL/SQL query statement below */\n \n RETURN result;\nEND;", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"228.6K\", \"totalSubmission\": \"636.6K\", \"totalAcceptedRaw\": 228626, \"totalSubmissionRaw\": 636582, \"acRate\": \"35.9%\"}", "hints": [], "solution": null, "status": null, "sampleTestCase": "{\"headers\": {\"Employee\": [\"id\", \"salary\"]}, \"argument\": 2, \"rows\": {\"Employee\": [[1, 100], [2, 200], [3, 300]]}}", "metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Employee (Id int, Salary int)\"\n ],\n \"mssql\": [\n \"Create table Employee (Id int, Salary int)\"\n ],\n \"oraclesql\": [\n \"Create table Employee (Id int, Salary int)\"\n ],\n \"database\": true,\n \"manual\": true\n}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [ "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')" ], "enableRunCode": true, "enableTestMode": false, "enableDebugger": false, "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"]}", "libraryUrl": null, "adminUrl": null, "challengeQuestion": null, "__typename": "QuestionNode" } } }