2017-10-19 4 views
1

이 또 다른 질문의 확장 : How to display null value when the record is present more than one time in oracle sql표시 널 (null) 값은

나는 테이블 같이 설정 한 다음

c_id c_name  c_tax 

1001 Element1 1 
1001 Element1 2 
1001 Element2 1 
1001 Element2 2 
1002 Element3 null 
1002 Element4 1 
1002 Element4 2 

는 내가 처음 column(c_id) 경우에 null을 표시 할 다음 조건에 기초하여 제 3의 column(c_tax)에 1 회 이상 예 또는 아니오로 표시됩니다.

Element1에는 두 개의 세금 1과 2가 있습니다. 따라서 을 한 번 표시하고 c_tax을 예로해야합니다. Element3에는 세금이 없으므로 null으로 표시되어야합니다.

내 출력은 다음과 같이한다 :

c_id c_name  c_tax 

1001 Element1 Yes 
null Element2 Yes 
1002 Element3 No 
null Element4 Yes 
+0

내부 stackoverlow 링크가 아니라 링크 서식을 사용하는 것보다, 원시 붙여 넣을 수 있습니다. –

답변

1

내가 제대로 이해한다면 :

select (case when row_number() over (partition by cid order by c_name) = 1 then cid end) as cid, 
     c_name, 
     (case when max(c_tax) is not null then 'yes' else 'no' end) as c_tax 
from t 
group by c_id, c_name 
order by c_id, c_name; 
+0

당신이 정확하게 이해했을뿐만 아니라 당신의 대답은 완벽합니다. 고맙습니다. @ Gordon Linoff – Santosh