sql - 使用 SQL 查找日期的最大值
问题描述
我需要 SQL Query 来按类型找出完成日期的最大值。如果特定类型的完成日期为空,则所有行都将为空,否则完成日期的最大值
解决方案
您可以使用窗口函数:
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
.
推荐阅读
- c# - 类 PerformanceCounter 文档
- xamarin - 在 Xamarin.Forms 中实现回收单元格网格的最佳方法?
- unit-testing - then Return中如何处理方法的不同返回类型?
- javascript - 禁用将浮动字符粘贴到输入数字字段的可能性
- javascript - 为什么重新加载有一半的时间返回一个空状态?
- google-translate - 谷歌翻译在某些主机上自我屏蔽?
- java - 如何从可以属于两个或多个组的列表中对对象进行分组?
- python - 将前导零添加到 NumPy 数组中的字符串
- java - ResponseEntity 主体在两个 Web 服务调用之间丢失
- python - 如何在 OpenCV Python 中加入附近的边界框