## 샘플 데이터
Row# CD SHOP_CD PER
1 SG A 9.37
2 SP B 14.71
3 SP A 5.71
Row# CD SHOP_CD PER
1 SG P 0
2 SG B 0
3 SG A 0
4 SP P 0
5 SP B 7.14
6 SP A 3.03
## CD 컬럼 기준으로 SHOP_CD 컬럼 데이터 그룹핑
with kk as (
select '1' as Row#, 'SG' as CD, 'A' as SHOP_CD, '9.37' as PER from dual
union all
select '2','SP','B','14.71' from dual
union all
select '3','SP','A','5.71' from dual
)
select CD,min(decode(cnt,1,SHOP_CD)) || ' & ' || min(decode(cnt,2,SHOP_CD))
from (select kk.*,row_number() over(partition by CD order by CD) cnt from kk) group by CD;
with kk as (
select '1' as Row#, 'SG' as CD, 'P' as SHOP_CD, '0' as PER from dual
union all
select '2','SG','B','0' from dual
union all
select '3','SG','A','0' from dual
union all
select '4','SP','P','5.71' from dual
union all
select '5','SP','B','7.14' from dual
union all
select '6','SP','A','3.03' from dual
)
select CD,min(decode(cnt,1,SHOP_CD)), min(decode(cnt,2,SHOP_CD)), min(decode(cnt,3,SHOP_CD))
from (select kk.*,row_number() over(partition by CD order by CD) cnt from kk)
group by CD;
'Oracle > oracle' 카테고리의 다른 글
hash_value VS sql_id (0) | 2012.07.17 |
---|---|
TRANSLATE 함수 사용법 (0) | 2012.01.04 |
Parameter DIRECT: Conventional Path Export Versus Direct Path Export [ID 155477.1] (0) | 2011.07.24 |
Append 힌트를 사용하려면 테이블을 NOLOGGING으로 설정해야 한다는 논란 (0) | 2011.07.06 |
sqlplus를 사용한 csv 파일 내려받기 (0) | 2011.06.27 |