如何使用case表达式或应该使用任何其他选项



我有一个类似这样的表,Report_table:

COMPLOTION_DATE2022年6月24日错误错误成功成功
Report_DEFINITION_NAME Report_CORE_NAME COMPLETION_STATUS
报告AD
报告BB 错误
报告AD AD2020年3月19日
报告R5
报告G8 G804-06-2022
报告R5
报告LH LH2019年9月7日
报告U6 U6 错误 2022年5月12日
报告AD AD2021年9月23日

所以,我使用了IN子句来解决我的问题,而没有Case表达式。

在select语句中获取最大值并使用父select语句中的in子句调用该语句解决了我的问题。类似于:

SELECT 
a.*,
a.completion_date,
b.completion_date AS last_success_date
FROM report_table a, report_table b
WHERE a.report_definition_name = b.report_definition_name
AND a.completion_date IN 
(
SELECT MAX(su.completion_date) 
FROM report_table su 
WHERE su.completion_status = 'Success'
AND b.report_definition_name = su.report_definition_name
)
ORDER BY a.completion_date DESC;

相关内容

最新更新