sql - BIGQUERY - LEFT OUTER JOIN 不能在没有连接两侧的字段相等的条件下使用
问题描述
我正在尝试使用此查询在 bigquery 中找到第五高的薪水,但它给了我错误
LEFT OUTER JOIN cannot be used without a condition that is an equality of fields from both sides of the join.
我相信对于这个问题,这是对 sql 的正确查询,但在 bigquery 中有些问题。有人可以帮我吗?:)
select concat(first_name, ' ', last_name) as Name, salary
from `table` w1
where 4 = (select count(distinct(salary))
from `table` w2
where w2.salary > w1.salary)
解决方案
您的查询似乎返回了具有四个较大薪水的行。那将是第五大薪水。所以,只需使用dense_rank()
:
select w.*
from (select w.*,
dense_rank() over (order by salary desc) as seqnum
from `table` w
) w
where seqnum = 5;
推荐阅读
- javascript - 在选择中显示不同的值
- angular - Angular 中的多个异步操作
- xml - 我的 Xpath 表达式导致 "$content-type": "application/xml;charset=utf-8" "$content": "PGNvbXBhc3NpZD4xMjI1NDI8L2NvbXBhc3NpZD4="
- yocto - 如何在 Yocto poky Warriors 的只读 rootfs 中更改时区
- javascript - 如何从文本文件中创建 html 选择下拉列表
- javascript - 创建两个 html 元素并将一个附加到另一个确实失败
- python - Pygame 文本显示错误的字体
- android - “支持的最低 Gradle 版本是 6.1.1。当前版本是 5.4.1。” 但 gradle-wrapper.properties 有 6.1.1
- docker - 我可以在 docker 中运行容器,但无法在浏览器中查看
- python - Python AsyncIO 流阅读器无法正确读取