database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
PostgreSQL
Firebird
ㆍOracle
Informix
Sybase
MS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
Oracle Q&A 40906 게시물 읽기
No. 40906
ROW 정보 가로로 표현하기
작성자
지혀니
작성일
2015-08-26 16:05
조회수
8,913

안녕하세요. ROW 정보를 가로로 표현하고자 합니다. (3개단위 씩)

그런데 빈공간이 남아서 빈공간을 없애고 싶은데 잘 안되어서 질문 드립니다.

WITH DD AS

(

SELECT '01' AS CD, 'A1' AS NM FROM DUAL

UNION ALL SELECT '02' AS CD, 'A2' AS NM FROM DUAL

UNION ALL SELECT '03' AS CD, 'A3' AS NM FROM DUAL

UNION ALL SELECT '04' AS CD, 'A4' AS NM FROM DUAL

UNION ALL SELECT '05' AS CD, 'A5' AS NM FROM DUAL

UNION ALL SELECT '06' AS CD, 'A6' AS NM FROM DUAL

UNION ALL SELECT '07' AS CD, 'A7' AS NM FROM DUAL

UNION ALL SELECT '08' AS CD, 'A8' AS NM FROM DUAL

UNION ALL SELECT '09' AS CD, 'A9' AS NM FROM DUAL

UNION ALL SELECT '10' AS CD, 'A10' AS NM FROM DUAL

UNION ALL SELECT '11' AS CD, 'A11' AS NM FROM DUAL

UNION ALL SELECT '12' AS CD, 'A12' AS NM FROM DUAL

UNION ALL SELECT '13' AS CD, 'A13' AS NM FROM DUAL

)

SELECT

MIN(DECODE(MOD(DD.CD, 3), 1, NM)) AS NM1

,MIN(DECODE(MOD(DD.CD, 3), 2, NM)) AS NM2

,MIN(DECODE(MOD(DD.CD, 3), 0, NM)) AS NM3

 

,MIN(DECODE(MOD(DD.CD, 3), 1, CD)) AS CD1

,MIN(DECODE(MOD(DD.CD, 3), 2, CD)) AS CD2

,MIN(DECODE(MOD(DD.CD, 3), 0, CD)) AS CD3

 

FROM DD

GROUP BY CD, NM

 

ORACLE 10 버전입니다. GROUP BY를 없애면 하나의 데이터만 나오고 둘다 사용하면 GROUP을 한거나 안한거나 똑같이 나오고

NM1 NM2 NM3 CD1 CD2 CD3

A2 02

A4 04

A3 03

A1 01

A5 05

A6 06

다음과 같이 표현 -->

NM1 NM2 NM3 CD1 CD2 CD3

A4 A2 A3 04 02 03

A1 A5 A6 01 05 06

 

미리 감사 드립니다.

 

이 글에 대한 댓글이 총 2건 있습니다.

 


WITH DD AS

(

    SELECT '01' AS CD, 'A1' AS NM FROM DUAL

    UNION ALL SELECT '02' AS CD, 'A2' AS NM FROM DUAL

    UNION ALL SELECT '03' AS CD, 'A3' AS NM FROM DUAL

    UNION ALL SELECT '04' AS CD, 'A4' AS NM FROM DUAL

    UNION ALL SELECT '05' AS CD, 'A5' AS NM FROM DUAL

    UNION ALL SELECT '06' AS CD, 'A6' AS NM FROM DUAL

    UNION ALL SELECT '07' AS CD, 'A7' AS NM FROM DUAL

    UNION ALL SELECT '08' AS CD, 'A8' AS NM FROM DUAL

    UNION ALL SELECT '09' AS CD, 'A9' AS NM FROM DUAL

    UNION ALL SELECT '10' AS CD, 'A10' AS NM FROM DUAL

    UNION ALL SELECT '11' AS CD, 'A11' AS NM FROM DUAL

    UNION ALL SELECT '12' AS CD, 'A12' AS NM FROM DUAL

    UNION ALL SELECT '13' AS CD, 'A13' AS NM FROM DUAL

)

SELECT MAX(DECODE(GP2,0,NM)) NM1

     , MAX(DECODE(GP2,1,NM)) NM2

     , MAX(DECODE(GP2,2,NM)) NM3

     , MAX(DECODE(GP2,0,CD)) CD1

     , MAX(DECODE(GP2,1,CD)) CD2

     , MAX(DECODE(GP2,2,CD)) CD3

FROM (

      SELECT CD, NM

           , FLOOR((ROWNUM-1)/3) GP1

           , MOD((ROWNUM-1),3) GP2

        FROM DD

)

GROUP BY GP1

ORDER BY CD1

;

 

창조의날개님이 2015-08-26 19:46에 작성한 댓글입니다. Edit

감사합니다.

 

어제 하루 종일 이것때문에 삽질했는데 님 덕분에 오자마자 해결했네요..

 

아침부터 어떻게 해야되나 걱정했었는데

 

너무 감사합니다.

 

행복한 나날 보내세요^^

지혀니님이 2015-08-27 08:27에 작성한 댓글입니다. Edit
[Top]
No.
제목
작성자
작성일
조회
40911같은 이름중에서 코드가 일부 상이한 번호 찾기 [5]
초보네
2015-08-27
8641
40910ssh로 sqlplus 실행 시 command not found [1]
새내기
2015-08-27
8699
40909dba_hist_sqlbind 관련 문의입니다.
이현정
2015-08-27
7692
40906ROW 정보 가로로 표현하기 [2]
지혀니
2015-08-26
8913
40905문자열과 숫자 분리하기 [1]
개발자
2015-08-24
8261
40904union 문의 [2]
이현정
2015-08-24
7932
40903SQL UPDATE 질문입니다. [2]
22일
2015-08-22
8457
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.019초, 이곳 서비스는
	PostgreSQL v16.4로 자료를 관리합니다