Oracle 中 return null 的最大函数

Max function to return null in Oracle

对于以下输入

Employee_ID Date_Column
100         12/12/2016
100         15/12/2016
200         19/12/2016

我使用了查询

select employee_id,Max(Date_Column),Min(Date_Column) from Employee_ID where Date_Column is not null Group by Employee_ID

检索最大和最小日期

但是如果我的 date_column 只有一个员工日期,则 Max 和 Min 函数返回相同的日期。

但我的预期输出是

employee_id Max(Date_Column) Min(Date_Column)
100         15/12/2016       12/12/2016
200          NULL            19/12/2016

非常感谢您的帮助

只有一个值,Oracle 代码是正确的。你可以用条件逻辑做你想做的事:

select employee_id,
       (case when max(date_column) <> min(date_column) then Max(Date_Column) end),
       Min(Date_Column)
from Employee_ID
where Date_Column is not null
Group by Employee_ID;