Mysql where子句中的数字如何影响sunquery
如果代码中的count函数给出了许多不同的薪水,那么where子句中的“3”是做什么的Mysql where子句中的数字如何影响sunquery,mysql,sql,Mysql,Sql,如果代码中的count函数给出了许多不同的薪水,那么where子句中的“3”是做什么的 select distinct salary from worker a where 3>= (select COUNT(distinct salary) from worker b where a .salary <=b.salary) 这是为了拿到前三名的薪水。然而,这是一种愚蠢的方法,因为这要简单得多: select distinct salar
select distinct salary
from worker a
where 3>= (select COUNT(distinct salary)
from worker b
where a .salary <=b.salary)
这是为了拿到前三名的薪水。然而,这是一种愚蠢的方法,因为这要简单得多:
select distinct salary
from worker w
order by salary desc
limit 3;
这种逻辑不再需要相关子查询,即使在更复杂的情况下也是如此。MySQL现在支持rank和row_number等功能,可以为您实现这一点。这是为了获得前三名的薪水。然而,这是一种愚蠢的方法,因为这要简单得多:
select distinct salary
from worker w
order by salary desc
limit 3;
这种逻辑不再需要相关子查询,即使在更复杂的情况下也是如此。MySQL现在支持rank和row_number等功能,可以为您执行此操作。此列表列出了工资较高的员工少于三人的所有员工,是吗?此列表列出了工资较高的员工少于三人的所有员工,是吗?