with my_table as(
SELECT
MAX(GUBUN) GUBUN, MAX(M) M, MAX(M2) M2, MAX(DIV) DIV, MAX(PER) PER
FROM
(
SELECT '멋쟁이' GUBUN, '' M, '' M2, '' DIV, '' PER FROM DUAL
UNION ALL
SELECT '' GUBUN, '3630' M, '' M2, '' DIV, '' PER FROM DUAL
UNION ALL
SELECT '' GUBUN, '' M, '2847' M2, '' DIV, '' PER FROM DUAL
UNION ALL
SELECT '' GUBUN, '' M, '' M2, '783' DIV, '' PER FROM DUAL
UNION ALL
SELECT '' GUBUN, '' M, '' M2, '' DIV, '27.5%' PER FROM DUAL
)
UNION ALL
SELECT
MAX(GUBUN) GUBUN, MAX(M) M, MAX(M2) M2, MAX(DIV) DIV, MAX(PER) PER
FROM
(
SELECT '못난이' GUBUN, '' M, '' M2, '' DIV, '' PER FROM DUAL
UNION ALL
SELECT '' GUBUN, '1' M, '' M2, '' DIV, '' PER FROM DUAL
UNION ALL
SELECT '' GUBUN, '' M, '2' M2, '' DIV, '' PER FROM DUAL
UNION ALL
SELECT '' GUBUN, '' M, '' M2, '1' DIV, '' PER FROM DUAL
UNION ALL
SELECT '' GUBUN, '' M, '' M2, '' DIV, '100%' PER FROM DUAL
))
select *from my_table;
sol)
with my_table as(
SELECT
MAX(GUBUN) GUBUN, MAX(M) M, MAX(M2) M2, MAX(DIV) DIV, MAX(PER) PER
FROM
(
SELECT '멋쟁이' GUBUN, '' M, '' M2, '' DIV, '' PER FROM DUAL
UNION ALL
SELECT '' GUBUN, '3630' M, '' M2, '' DIV, '' PER FROM DUAL
UNION ALL
SELECT '' GUBUN, '' M, '2847' M2, '' DIV, '' PER FROM DUAL
UNION ALL
SELECT '' GUBUN, '' M, '' M2, '783' DIV, '' PER FROM DUAL
UNION ALL
SELECT '' GUBUN, '' M, '' M2, '' DIV, '27.5%' PER FROM DUAL
)
UNION ALL
SELECT
MAX(GUBUN) GUBUN, MAX(M) M, MAX(M2) M2, MAX(DIV) DIV, MAX(PER) PER
FROM
(
SELECT '못난이' GUBUN, '' M, '' M2, '' DIV, '' PER FROM DUAL
UNION ALL
SELECT '' GUBUN, '1' M, '' M2, '' DIV, '' PER FROM DUAL
UNION ALL
SELECT '' GUBUN, '' M, '2' M2, '' DIV, '' PER FROM DUAL
UNION ALL
SELECT '' GUBUN, '' M, '' M2, '1' DIV, '' PER FROM DUAL
UNION ALL
SELECT '' GUBUN, '' M, '' M2, '' DIV, '100%' PER FROM DUAL
))
select decode(cnt,1,'M',decode(cnt,2,'M2',decode(cnt,3,'DIV','PER'))) as 구분,
min(decode(gubun,'멋쟁이',decode(cnt,1,M,2,M2,3,div,4,per))) as 멋쟁이,
min(decode(gubun,'못난이',decode(cnt,1,M,2,M2,3,div,4,per))) as 못난이
from my_table,(SELECT ROWNUM CNT
FROM USER_TABLES
WHERE ROWNUM<5)
group by cnt
order by cnt;
'개발하자 > ORACLE' 카테고리의 다른 글
최대값과 최소값 제외한 평균,총합 구하기(GREATEST,LEAST) (0) | 2015.02.09 |
---|---|
문자만 자르기(정규식함수 사용-REGEXP_SUBSTR) (0) | 2015.02.09 |
동일 컬럼값 안보여주기 (0) | 2015.02.06 |
학년별로 가공후 중복된 칼럼 이름 안보이게 하기(3가지 풀이법) (0) | 2015.02.06 |
사원의 급여 합계 ,평균 및 부서별 직원수 뽑기 (0) | 2015.02.06 |