在TABLE_A中,每個ID都有一個最小SDT和最大EDT。ORACLE SQL Query記錄日期位於其他表的最短和最長日期之間
例如:對於ID = 1000,這將是1/09/2013和3/10/2013。
例如:對於ID = 1001,這將是1/07/2013和3/08/2013。
預期的結果將是來自TABLE_B的所有記錄,其中來自TABLE_B的SDT落在這些最小SDT和來自TABLE_A的最大EDT值之間。
TABLE_A
ID SDT EDT
------------------------------
1000 1/10/2013 3/10/2013
1000 1/09/2013 3/09/2013
1001 1/08/2013 3/08/2013
1001 1/07/2013 3/07/2013
1002 1/06/2013 3/06/2013
表-B
ID SDT
-----------------
1000 2/10/2013 ===> because it falls between 1/09/2013 and 3/10/2013
1000 4/09/2013 ===> because it falls between 1/09/2013 and 3/10/2013
1001 2/08/2013 ===> because it falls between 1/07/2013 and 3/08/2013
1001 4/05/2013 ==> not in result because it's not between 1/07/2013 and 3/08/2013
1002 4/06/2013 ==> also out of range, so not in results
它沒有返回正確的答案:http://www.sqlfiddle.com/#!4/a196f4/14 – Laurence
啊,我第一次讀這篇文章時錯過了分組要求。你是正確的先生。 :) 如果它正在尋找BETWEEN匹配個別行,那麼我的查詢將有正確的。 – MeyerRJ