最近在做leetcode上数据库的题,如何返回第N大的值。题目如下:
Write a SQL query to get the nth highest salary from the Employee table.
+----+--------+
| Id | Salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+
解答代码:
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
SET N=N-1;
RETURN (
# Write your MySQL query statement below
select
Salary
from Emplo

本文介绍了在LeetCode上解决返回数据库中第N大数值的问题,通过解析解答代码,重点讲解了MySQL中`LIMIT`子句的使用,包括`LIMIT n`和`LIMIT n OFFSET m`的语法,以及在大数据查询中用`GROUP BY`代替`DISTINCT`进行去重提高效率的方法。
&spm=1001.2101.3001.5002&articleId=51736685&d=1&t=3&u=f8c16d0a66ee4567b0a4881ee81f3b7f)

被折叠的 条评论
为什么被折叠?



