首页 > 解决方案 > 使用 SQL 查找日期的最大值

问题描述

我需要 SQL Query 来按类型找出完成日期的最大值。如果特定类型的完成日期为空,则所有行都将为空,否则完成日期的最大值

在此处输入图像描述

标签: sqloracle

解决方案


您可以使用窗口函数:

select t.*,
       (case when count(*) over (partition by type) = count(done_date) over (partition by type)
             then max(done_date) over (partition by type)
        end) as last_date
from t;

第一个条件是NULL检查done_date.


推荐阅读