我试图在谷歌上搜索一个解决方案,并尝试了一两个建议,但我能找到的例子似乎没有用于跨表日期,甚至 Oracle。另外,我对 SQL 的理解相当有限,但我学到的大部分知识都来自这里,所以我感谢我的帮助。5 U. e) x! X w- @: C1 a
编辑:另一个条件是我只想返回相关事件/文档类型。所以我只想把它带回 DOC_TYPE 是查询或信息DOC_ID,Event_Type 也是如此。 5 O0 ~! w, g7 E9 _/ D编辑:谢谢文森特,我会按照建议 where 放入(我想我在任何地方都试过了。!),现在我得到了所需的结果。5 Q) v6 \- K/ ^1 S
如果有人感兴趣,我将在未来发布工作解决方案供参考:4 m; r5 _6 ?- L
SELECT*FROM (SELECT O_ASSESSMENTS.ASM_SUBJECT_ID as "ID",O_ASSESSMENTS.ASM_ID as "Assessment ID",O_ASSESSMENTS.ASM_START_DATE as "Assessment Start", O_ASSESSMENTS.ASM_END_DATE as "Assessment End",O_SERVICE_EVENTS.SEV_ID as "Event ID",O_SERVICE_EVENTS.SEV_ACTUAL_DATE as "Event Start",O_SERVICE_EVENTS.SEV_OUTCOME_DATE as "Event End",ROUND(O_ASSESSMENTS.ASM_START_DATE -O_SERVICE_EVENTS.SEV_ACTUAL_DATE,0) as "Likely", row_number() over(PARTITION BY O_ASSESSMENTS.ASM_ID ORDER BY abs(O_ASSESSMENTS.ASM_START_DATE - O_SERVICE_EVENTS.SEV_ACTUAL_DATE)) rn FROM O_ASSESSMENTS JOIN O_SERVICE_EVENTS ON O_ASSESSMENTS.ASM_SUBJECT_ID = O_SERVICE_EVENTS.SEV_SUBJECT_IDWhere O_SERVICE_EVENTS.SEV_CODE IN ('t','t1') AND O_ASSESSMENTS.ASM_QSA_ID IN ('test','test ) WHERE rn = 1 ' ]! C' x! k4 o