WITH M AS ( SELECT 1 MON, 25697 AS A, 45180 AS B, 44741 AS C, 26136 AS D FROM DUAL UNION ALL SELECT 2, NULL, 30774, 29024, 1750 FROM DUAL UNION ALL SELECT 3, NULL, 44789, 48517, 3728 FROM DUAL UNION ALL SELECT 4, NULL, 45835, 42150, 3685 FROM DUAL UNION ALL SELECT 5, NULL, 142204, 106020, 36184 FROM DUAL UNION ALL SELECT 6, NULL, NULL, NULL, NULL FROM DUAL ORDER BY MON ) SELECT '기초재고' , MIN(CASE MON WHEN 1 THEN A END) '1Mon' , MIN(CASE MON WHEN 1 THEN D END) '2Mon' , MIN(CASE MON WHEN 2 THEN D END) '3Mon' , MIN(CASE MON WHEN 3 THEN D END) '4Mon' , MIN(CASE MON WHEN 4 THEN D END) '5Mon' , MIN(CASE MON WHEN 5 THEN D END) '6Mon' FROM M UNION ALL SELECT '매입수량' , MIN(CASE MON WHEN 1 THEN B END) '1Mon' , MIN(CASE MON WHEN 2 THEN b END) '2Mon' , MIN(CASE MON WHEN 3 THEN b END) '3Mon' , MIN(CASE MON WHEN 4 THEN b END) '4Mon' , MIN(CASE MON WHEN 5 THEN b END) '5Mon' , MIN(CASE MON WHEN 6 THEN b END) '6Mon' FROM M UNION ALL SELECT '매출수량' , MIN(CASE MON WHEN 1 THEN c END) '1Mon' , MIN(CASE MON WHEN 2 THEN c END) '2Mon' , MIN(CASE MON WHEN 3 THEN c END) '3Mon' , MIN(CASE MON WHEN 4 THEN c END) '4Mon' , MIN(CASE MON WHEN 5 THEN c END) '5Mon' , MIN(CASE MON WHEN 6 THEN c END) '6Mon' FROM M UNION ALL SELECT '기말재고' , MIN(CASE MON WHEN 1 THEN d END) '1Mon' , MIN(CASE MON WHEN 2 THEN d END) '2Mon' , MIN(CASE MON WHEN 3 THEN d END) '3Mon' , MIN(CASE MON WHEN 4 THEN d END) '4Mon' , MIN(CASE MON WHEN 5 THEN d END) '5Mon' , MIN(CASE MON WHEN 6 THEN d END) '6Mon' FROM M
WITH M AS ( SELECT '기초재고' AS TYP_NM, 'A' AS TYP, 25697 AS JAN, NULL AS FEB, NULL AS MAR, NULL AS APR, NULL AS MAY, NULL AS JUN FROM DUAL UNION ALL SELECT '매입수량' AS TYP_NM, 'B' AS TYP, 45180 AS JAN, 30774 AS FEB, 44789 AS MAR, 45835 AS APR, 142204 AS MAY, NULL AS JUN FROM DUAL UNION ALL SELECT '매출수량' AS TYP_NM, 'C' AS TYP, 44741 AS JAN, 29024 AS FEB, 48517 AS MAR, 42150 AS APR, 106020 AS MAY, NULL AS JUN FROM DUAL UNION ALL SELECT '기말재고' AS TYP_NM, 'D' AS TYP, 26136 AS JAN, 1750 AS FEB, 3728 AS MAR, 3685 AS APR, 36184 AS MAY, NULL AS JUN FROM DUAL ) SELECT TYP_NM , TYP , JAN , CASE TYP WHEN 'A' THEN LEAD(JAN, 3) OVER (ORDER BY TYP) ELSE FEB END AS FEB , CASE TYP WHEN 'A' THEN LEAD(FEB, 3) OVER (ORDER BY TYP) ELSE MAR END AS MAR , CASE TYP WHEN 'A' THEN LEAD(MAR, 3) OVER (ORDER BY TYP) ELSE APR END AS APR , CASE TYP WHEN 'A' THEN LEAD(APR, 3) OVER (ORDER BY TYP) ELSE MAY END AS MAY , CASE TYP WHEN 'A' THEN LEAD(MAY, 3) OVER (ORDER BY TYP) ELSE JUN END AS JUN FROM M