首页 > 解决方案 > 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)

标签: sqlgoogle-bigquery

解决方案


您的查询似乎返回了具有四个较大薪水的行。那将是第五大薪水。所以,只需使用dense_rank()

select w.*
from (select w.*,
             dense_rank() over (order by salary desc) as seqnum
      from `table` w
     ) w
where seqnum = 5;

推荐阅读