📜  门| GATE CS Mock 2018 |问题 19

📅  最后修改于: 2021-09-26 04:11:46             🧑  作者: Mango

考虑以下关系模式:

EmployeeDetail (EmpId, FullName, ManagerID, DateOfJoining)
EmployeeSalary (EmpID, Project, Salary)

考虑对上述数据库的以下关系查询:

SELECT Salary
FROM EmployeeSalary Emp1
WHERE 2 = (
                SELECT COUNT( DISTINCT ( Emp2.Salary ) )
                FROM EmployeeSalary Emp2
                WHERE Emp2.Salary > Emp1.Salary
            )

假设上述模式对应的关系不为空。以下哪一项是上述查询的正确解释?
(A)从表中找出最高工资
(B)从表中找出第二高的薪水
(C)从表中找出第三高的薪水
(D)以上都不是答案: (C)
说明:对于第 n 高的薪水-

SELECT Salary
FROM EmployeeSalary Emp1
WHERE n-1 = (
                SELECT COUNT( DISTINCT ( Emp2.Salary ) )
                FROM EmployeeSalary Emp2
                WHERE Emp2.Salary > Emp1.Salary
            )

选项(C)是正确的。
这个问题的测验