【发布时间】:2019-02-08 12:35:06
【问题描述】:
表 AA
table AA
ID Date
1 2018.01.21
2 2018.01.22
2 2018.05.27
2 2018.07.15
table BB
ID Date
1 2017.05.21
1 2017.08.27
1 2018.01.23
1 2018.02.15
2 2017.01.01
2 2017.05.31
2 2018.01.01
2 2018.01.25
2 2018.05.29
2 2018.09.30
我想在 ID 列上加入这些表。目的是在表 B 中查找与表 A 中的最小日期相同或晚于每个 id 和日期的日期(在表 A 上的每行)。
我的意思是输出应该是
OUTPUT
1 2018.01.23
2 2018.01.25
2 2018.05.29
2 2018.09.30
提前致谢
【问题讨论】:
-
你说
And the purpose is find the min date on table B which is bigger equal (>=) than table A.,但你的输出几乎读起来像the purpose is to find dates in table B that are the same as or later than the min date in table A, per id。哪个是对的?您的输出应该每个 id 有一行,或者每个 id 应该有多行(因为 id = 1,表 B 中有两行大于表 A 中的任一行,但您的输出只显示一行。但是,输出中有多个 id = 2 的 rws。) -
不应该在输出中包含
2018.02.15for id = 1 的行吗?如果不是,为什么不呢?它大于2018.01.21。 -
展示你的尝试
-
对于 ID=1,(id =1 和日期 = 2018.01.21)的最小输出是表 B 上的 2018.01.23
标签: sql oracle join oracle11g greatest-n-per-group