분석함수를 사용하면 안 된다는 말씀이신가요?
id = 300의 경우 S가 여러개이면 여러가 모두 출력하는 건가요?
단순히 row_number() over만 사용 안 하는 것이고 id별로 단 1건만 표현하는 것이라면
with t as ( select '100' id, 'aaaa1' userid, 'M' type from dual union all select '100' id, 'aaaa2' userid, 'S' type from dual union all select '100' id, 'aaaa3' userid, 'S' type from dual union all select '200' id, 'bbbb1' userid, 'M' type from dual union all select '200' id, 'bbbb2' userid, 'S' type from dual union all select '300' id, 'cccc1' userid, 'S' type from dual ) select id, min(userid) keep (dense_rank first order by type) userid, min(type) type from t group by id
이런 형태도 가능할 거 같은데요.
아니면 이렇게..
select * from t x where type = 'M' or not exists (select 1 from t y where y.id = x.id and type = 'M')
이렇게 하면 같은 id에 대해 M값이나 S값이 중복되어도 다 나오겠네요.
안나오게 하려면 group by id해주면 될 것 같구요.
WITH t1 AS
(SELECT 100 ID, 'aaaa1' userid, 'M' div FROM dual UNION ALL
SELECT 100, 'aaaa2', 'S' FROM dual UNION ALL
SELECT 100, 'aaaa3', 'S' FROM dual UNION ALL
SELECT 200, 'bbbb1', 'M' FROM dual UNION ALL
SELECT 200, 'bbbb2', 'S' FROM dual UNION ALL
SELECT 300, 'cccc1', 'S' FROM dual)
SELECT ID, userid, div
FROM t1 b
WHERE (b.id, b.div) IN (SELECT ID
,min(div)
FROM t1 a
GROUP BY ID)
ORDER BY ID, userid