首页 > 解决方案 > 不能按数据分组

问题描述

输入

A   B    date
--------------------
00  12   22-01-2019
00  12   null
00  25   22-01-2019
00  24   22-01-2019 

根据上述数据,我需要以下输出:

  A   B    date
--------------------
 00  12    null
 00  25    22-01-2019
 00  24   22-01-2019

我需要从表中获取打开、关闭的记录。

如果我使用的日期为空,则不会出现其他现有记录。

我需要在 B 列中应用条件。

如果 Column B 列的 date 中有 null 值,则 null 将显示,否则如果 null 和非 null 值都为 null,则将输出 date null。

Select a,b,date 
from table1,table2
where ...
group by a,b,date

标签: sqloracle

解决方案


聚合函数会忽略空值,因此您需要分析版本

select a, b, min(date_) keep (dense_rank first order by date_ nulls first) 
  from input group by a, b

演示


推荐阅读