select distinct id, sd, feed
from (select id, sd, feed, max(feed) over(partition by id, sd) as mf from t)
where (feed is not null and mf is not null)
or (feed is null and mf is null)
order by id, sd, feed
我明白使用聚合函数max和组,你想要每个组合的(ID
,SD
)a的所有不同值FEED
只有在没有其他值存在的情况下才为空。而不是max()
,您可以使用min()
在analytic version。
测试:
create table t (ID varchar2(10), SD varchar2(10), FEED varchar2(10));
insert into t values (0016, '21AE', 'GF-HF');
insert into t values (0016, '21AE', 'GF-HF');
insert into t values (0016, '21AE', 'AF-AF');
insert into t values (0016, '21AE', null);
insert into t values (0017, '21BE', 'FF-HF');
insert into t values (0017, '21BE', null);
insert into t values (0018, '21CE', 'CF-HF');
insert into t values (0018, '21CE', null);
insert into t values (0019, '21DE', null);
insert into t values (0019, '21DE', null);
ID SD FEED
---------- ---------- ----------
16 21AE AF-AF
16 21AE GF-HF
17 21BE FF-HF
18 21CE CF-HF
19 21DE
其值应有所回升,当属性不为空? –
你有试过吗?如果不起作用呢? – Lexi
'你可以通过id,sd'选择id,sd,max(FEED) –