sql - 如何在sql中使用group by、order by和where条件?
问题描述
给定表包含
employee_id,
Month_Year,
Salary,
City
编写查询以获得每个城市的第五高年薪员工。
我的代码:
select * from (select * from(select * from (select * from dummy order by sal desc) where rownum <= 5) order by sal) where rownum <=1 ;
但这仅在总表中排名第五。
我想在哪里使用 group by 语句?
提前致谢。
解决方案
你可以试试下面 -
select *
from tablename as t1
where
t1.salary = (select salary from tablename t2
where
t2.city= t1.city ORDER by salary desc limit 1 offset 5)
推荐阅读
- javascript - 在赛普拉斯中使用 2 个条件和 IF 语句
- javascript - 如何移动对面的元素?html,css,js
- webi - Webi 的 LISTAGG 分区
- android - 具有多个操作的多个通知
- python - 如何分组和绘制聚合值
- reactjs - 如何在组件渲染发生之前检查条件?
- ffmpeg - 我可以在生成的 ffmpeg 视频上测试 nvidia 解码器(nvdec/cuvid)的功能吗?
- swift - 使用自定义 segue 时出现 Swift 约束问题
- c++ - Getting several WM_PAINT message with one dispatch
- html - iframe 中的链接正常,但不显示在嵌入页面中