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) –