반응형
Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- RabbitMQ
- WebLogic
- grafana
- JPA
- netflix oss
- docker-compose
- Selenium
- cassandra
- docker compose mysql
- vue.js
- coalesce
- Redis Sentinel
- jmeter
- spring boot
- argo cd
- Airflow
- docker
- spring cloud
- redis
- spring boot redis
- KAFKA
- Hibernate
- weblogic 10
- mybatis
- Spring Open Feign
- Netty
- Docker Compose
- QueryDSL
- MySQL
- ChannelPipeline
Archives
- Today
- Total
IT.FARMER
SQL(ORACLE) 여러 행의 특정 컬럼값 -> 하나의 컬럼으로 합치기 본문
반응형
connect by prior / sys_connect_by_path
with t as (
select 1 key1, '가' key2, '나' key3, 10 key4 from dual union all
select 2 key1, '가' key2, '나' key3, 20 key4 from dual union all
select 3 key1, '다' key2, '라' key3, 30 key4 from dual union all
select 4 key1, '다' key2, '라' key3, 40 key4 from dual union all
select 5 key1, '다' key2, '라' key3, 50 key4 from dual union all
select 6 key1, '마' key2, '바' key3, 60 key4 from dual union all
select 7 key1, '마' key2, '바' key3, 70 key4 from dual union all
select 8 key1, '가' key2, '다' key3, 10 key4 from dual
)
select key2
, key3
, substr(max(sys_connect_by_path(key1||':'||key4, ',')), 2)
from (select key1
, key2
, key3
, key4
, row_number() over(partition by key2, key3 order by key4) rn
from t
)
start with rn = 1
connect by prior key2 = key2 and prior rn = rn-1
group by key2
, key3
with t as (
select 1 key1, '가' key2, '나' key3, 10 key4 from dual union all
select 2 key1, '가' key2, '나' key3, 20 key4 from dual union all
select 3 key1, '다' key2, '라' key3, 30 key4 from dual union all
select 4 key1, '다' key2, '라' key3, 40 key4 from dual union all
select 5 key1, '다' key2, '라' key3, 50 key4 from dual union all
select 6 key1, '마' key2, '바' key3, 60 key4 from dual union all
select 7 key1, '마' key2, '바' key3, 70 key4 from dual union all
select 8 key1, '가' key2, '다' key3, 10 key4 from dual
)
select key2
, key3
, substr(max(sys_connect_by_path(key1||':'||key4, ',')), 2)
from (select key1
, key2
, key3
, key4
, row_number() over(partition by key2, key3 order by key4) rn
from t
)
start with rn = 1
connect by prior key2 = key2 and prior rn = rn-1
group by key2
, key3
반응형
'DataBase > oracle' 카테고리의 다른 글
SELECT 로 Query문 만들기 (0) | 2010.04.14 |
---|---|
ORACLE 월별 통계 (1~12월 표현) (2) | 2010.03.15 |
일별 통계 작성법(ORACLE) (0) | 2010.03.13 |
Oracle MERGE INTO(1/2) (0) | 2010.02.07 |
Oracle MERGE INTO(1/1) (0) | 2010.02.07 |