select t_code, name
from test
where t_code IN ('155','156')
결과값
t_code | name
155 t1
155 t2
156 t3
156 t4
이런 값이 나오는데 top1을 사용하지않고
select t_code, name
from test
where t_code IN ('155','156')
t_code | name
155 t1
156 t3
이런식으로 값이 하나씩만 나올수있도록 할수있을까요?
group by 는 name 때문에 안되고..답답해서 질문드립니다 ㅜㅜ
데이터가 얼마나 더 있고 어떤 형식인지 잘 모르겠으나... 도움이 되려나 모르겠네요..
with test (t_code, name) as
(
select 155, 't1' union all
select 155, 't2' union all
select 156, 't3' union all
select 156, 't4'
)
select *
from (
select ROW_NUMBER() over(partition by t_code order by name) as num
, t_code, name
from test
where t_code IN ('155','156')
) as z
where z.num = 1
;with test (t_code, name) as
(
select 155, 't1' union all
select 155, 't2' union all
select 156, 't3' union all
select 156, 't4'
)
select t_code, min(name) as name
from test
where t_code IN ('155','156')
group by t_code