我有一张桌子
NAME ID ORIGSSID$
------------------------------ ----- ---------
Reproducibility Renamed 2 1287 1088
Reproducibility Renamed 1284 1088
NoiseDrift 1049 1049
Reproducibility_8h 1131 1131
Reproducibility 1088 1088
Noise and Drift 1263 1049
我需要根据两个标准选择行:
ID
和ORIGSSID$
相等且COUNT(ORIGSSID$) == 1
OR
ORIGSSID$
,请选择最大ID
我的预期结果是:
NAME ID ORIGSSID$
------------------------------ ----- ---------
Reproducibility Renamed 2 1287 1088
Reproducibility_8h 1131 1131
Noise and Drift 1263 1049
请帮我构建SELECT表达式..
答案 0 :(得分:2)
根据您的两个条件,逻辑似乎是:
select name, id, ORIGSSID$
from (select t.*,
max(id) over (partition by ORIGSSID$) as maxid,
count(*) over (partition by ORIGSSID$) as cnt
from TABLE.SUBTABLE t
) t
where id = ORIGSSID$ or (id = maxid and cnt > 1);
根据您的示例结果,您似乎想要:
select name, id, ORIGSSID$
from (select t.*,
max(id) over (partition by ORIGSSID$) as maxid
from TABLE.SUBTABLE t
) t
where id = maxid;