mysql - 此版本的 MySQL 尚不支持 'LIMIT & IN/ALL/ANY/SOME 子查询'同时提取第 6 大薪水
问题描述
我编写了 Mysql 查询,该查询从员工表中提取了第 6 大的薪水。我浏览了其他堆栈溢出链接,也请不要将其设为重复。
我的查询是如何通过子查询中的限制。
下面的代码是内部连接工作正常
select e1.first_name,e1.salary
from employees e1
inner join (select employee_id
from employees
order by salary desc limit 6) as e2
on e1.employee_id = e2.employee_id
order by salary asc limit 1;
| first_name | salary |
+------------+--------+
| Barby | 164588 |
当我在子查询中写入时在子查询中传递限制时抛出错误
select first_name,salary
from employees
where employee_id in (select employee_id
from employees
order by salary desc **limit 6** )
order by salary desc limit 6;
| first_name | salary |
+------------+--------+
| Jacklyn | 166976 |
| Carissa | 166765 |
| Riley | 166569 |
| Lauren | 166016 |
| Lucy | 165660 |
| Barby | 164588 |
想要的结果在下面我想在子查询中写而不是加入
| first_name | salary |
+------------+--------+
| Barby | 164588 |
解决方案
推荐阅读
- reactjs - history.push 不适用于 React 中的某些重定向情况
- java - CEP 库中的连续性和状态存储
- apache-kafka - Kafka 主题的理想分区数
- css - 悬停时一个元素的 CSS 过渡不平滑,但当鼠标移开时是平滑的
- python - 属性错误:模块“tensorflow”没有属性“contrib”
- python - 无法将符号 Keras 输入/输出转换为简单 CNN 中的 numpy 数组
- r - 如何选择第一个实例,每个人,每个条件?
- excel - 带有 Vlookup 的验证下拉列表
- laravel - Laravel vue惯性创建分页搜索时出错
- asp.net-core - .Net Core 3.1 EdmModel的Json序列化