以下查询在MySql中无效。
SELECT * /*This is the outer query part */
FROM Employee Emp1
WHERE (N-1) = ( /* Subquery starts here */
SELECT COUNT(DISTINCT(Emp2.Salary))
FROM Employee Emp2
WHERE Emp2.Salary > Emp1.Salary)
帮助我。
答案 0 :(得分:5)
试试这个:
SET @n := 0;
SELECT * FROM
(SELECT salary, @n := @n + 1 AS t1 FROM Employee ORDER BY salary DESC)
AS t
WHERE t1 <= 5
<强> Working DEMO 强>