【发布时间】:2021-10-12 13:44:01
【问题描述】:
我有一个表 (table_old),其中有一列 (person_id) 有时具有重复值。我想为person_id 的每个值添加一个最大值为age_at_midmonth 的列。 Table_old 有 27,236,296 行。 Table_new 有 27,209,850 行。行数不应减少,因为这是一个没有 WHERE 子句的 LEFT JOIN。这里发生了什么?我做错了吗?有没有更好的办法?查询正在 Oracle 中运行。
create table schema1.table_new as
select
t1.*,
t2.current_age
from
schema1.table_old t1
left join (
select person_id, max(age_at_midmonth) as current_age
from schema1.table_old
group by person_id
) t2
on t1.person_id = t2.person_id;
【问题讨论】:
-
左连接不应该返回更少的行。
-
我很好奇为什么这个问题被否决了。我知道我在这里犯了一个愚蠢的错误,但我认为问题本身写得很好而且很清楚。我没有生气或什么,只是想知道。