使用时间戳对多个表进行左连接
好吧,SQL 和 Oracle 专家,我正在尝试构建一个有点复杂的查询。
这是我当前的查询:
select distinct person_info.person_name
table2.value,
table3.value,
table4.value,
table5.value
from person_info
left join table2 on table2.person_name=person_info.person_name
left join table3 on table3.person_name=person_info.person_name
left join table4 on table4.person_name=person_info.person_name
left join table5 on table5.person_name=person_info.person_name;
每个表的主键都是 person_name
和 timestamp
。现在我的问题是,如果表中存在同一个 person_name
的多个实例,那么我只想在最近的一个上left join
。有谁知道如何将此行为添加到此查询中?我正在使用甲骨文。
谢谢!
Ok SQL and Oracle gurus I have a somewhat complicated query that I'm trying to build.
Here is my current query:
select distinct person_info.person_name
table2.value,
table3.value,
table4.value,
table5.value
from person_info
left join table2 on table2.person_name=person_info.person_name
left join table3 on table3.person_name=person_info.person_name
left join table4 on table4.person_name=person_info.person_name
left join table5 on table5.person_name=person_info.person_name;
The primary key for every table is both the person_name
and a timestamp
. Now my problem is that if multiple instances of the same person_name
exist in a table then I only want to left join
on the most recent one. Does anyone know how to add this behavior to this query? I am using Oracle.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
Try: