下面有一个查询示例,但它将永远运行。。如果我做了联合,那么我必须复制整个大型查询。。有什么帮助吗
select columns
from table a
join (select *
from ( select *, row_number() over( partition BY id ORDER BY date ) row_seq
from table b
) where row_seq = 1
) o ON a.id = o.id OR a.id = o.src_id
left join table p on a.partner_c = p.id
left join table pp on a.parnt_id = pp.id
1条答案
按热度按时间fiei3ece1#
内部
可以使用以下限定子句编写:
可以推进到cte中,如:
也就是说你可以把整件事结合起来
table a
以及raw_rows o
```WITH raw_rows AS (
select *,
from table b
qualify row_number() over( partition BY id ORDER BY date ) = 1
), a_and_o AS (
select a.columns
,o.columns
from table a
join raw_rows o ON a.id = o.id
)
select columns
from a_and_o a
left join table p on a.partner_c = p.id
left join table pp on a.parnt_id = pp.id
join raw_rows o ON a.id = o.src_id AND o.src_id != o.id