Search

'월별'에 해당되는 글 2건

  1. 2018.04.06 [ORACLE]WMSYS.WM_CONCAT 월별데이터 합치기
  2. 2010.06.29 [MSSQL]일별,주별,월별 통계

[ORACLE]WMSYS.WM_CONCAT 월별데이터 합치기

Database 2018.04.06 09:17 Posted by 애플자라

SELECT 
    GROUP_NAME,
    REPLACE(REPLACE(WMSYS.WM_CONCAT(DISTINCT MARKETING_DATE_01),',','<br/>'),'(Meeting)','') AS DATE_01,

    REPLACE(REPLACE(WMSYS.WM_CONCAT(DISTINCT MARKETING_DATE_02),',','<br/>'),'(Meeting)','') AS DATE_02,

    REPLACE(REPLACE(WMSYS.WM_CONCAT(DISTINCT MARKETING_DATE_03),',','<br/>'),'(Meeting)','') AS DATE_03,

    REPLACE(REPLACE(WMSYS.WM_CONCAT(DISTINCT MARKETING_DATE_04),',','<br/>'),'(Meeting)','') AS DATE_04,

    REPLACE(REPLACE(WMSYS.WM_CONCAT(DISTINCT MARKETING_DATE_05),',','<br/>'),'(Meeting)','') AS DATE_05,

    REPLACE(REPLACE(WMSYS.WM_CONCAT(DISTINCT MARKETING_DATE_06),',','<br/>'),'(Meeting)','') AS DATE_06,

    REPLACE(REPLACE(WMSYS.WM_CONCAT(DISTINCT MARKETING_DATE_07),',','<br/>'),'(Meeting)','') AS DATE_07,

    REPLACE(REPLACE(WMSYS.WM_CONCAT(DISTINCT MARKETING_DATE_08),',','<br/>'),'(Meeting)','') AS DATE_08,

    REPLACE(REPLACE(WMSYS.WM_CONCAT(DISTINCT MARKETING_DATE_09),',','<br/>'),'(Meeting)','') AS DATE_09,

    REPLACE(REPLACE(WMSYS.WM_CONCAT(DISTINCT MARKETING_DATE_10),',','<br/>'),'(Meeting)','') AS DATE_10,

    REPLACE(REPLACE(WMSYS.WM_CONCAT(DISTINCT MARKETING_DATE_11),',','<br/>'),'(Meeting)','') AS DATE_11,

    REPLACE(REPLACE(WMSYS.WM_CONCAT(DISTINCT MARKETING_DATE_12),',','<br/>'),'(Meeting)','') AS DATE_12

FROM (SELECT GROUP_NAME,
       MARKETING_DATE,
       CASE WHEN SUBSTR (MARKETING_DATE, 6, 2) = '01' THEN MARKETING_DATE END MARKETING_DATE_01,
       CASE WHEN SUBSTR (MARKETING_DATE, 6, 2) = '02' THEN MARKETING_DATE END MARKETING_DATE_02,
       CASE WHEN SUBSTR (MARKETING_DATE, 6, 2) = '03' THEN MARKETING_DATE END MARKETING_DATE_03,
       CASE WHEN SUBSTR (MARKETING_DATE, 6, 2) = '04' THEN MARKETING_DATE END MARKETING_DATE_04,
       CASE WHEN SUBSTR (MARKETING_DATE, 6, 2) = '05' THEN MARKETING_DATE END MARKETING_DATE_05,
       CASE WHEN SUBSTR (MARKETING_DATE, 6, 2) = '06' THEN MARKETING_DATE END MARKETING_DATE_06,
       CASE WHEN SUBSTR (MARKETING_DATE, 6, 2) = '07' THEN MARKETING_DATE END MARKETING_DATE_07,
       CASE WHEN SUBSTR (MARKETING_DATE, 6, 2) = '08' THEN MARKETING_DATE END MARKETING_DATE_08,
       CASE WHEN SUBSTR (MARKETING_DATE, 6, 2) = '09' THEN MARKETING_DATE END MARKETING_DATE_09,
       CASE WHEN SUBSTR (MARKETING_DATE, 6, 2) = '10' THEN MARKETING_DATE END MARKETING_DATE_10,
       CASE WHEN SUBSTR (MARKETING_DATE, 6, 2) = '11' THEN MARKETING_DATE END MARKETING_DATE_11,
       CASE WHEN SUBSTR (MARKETING_DATE, 6, 2) = '12' THEN MARKETING_DATE END MARKETING_DATE_12,
       ROW_NUMBER () OVER (PARTITION BY GROUP_NAME ORDER BY MARKETING_DATE) RNUM
  FROM TB_MARKETING
 WHERE     SUBSTR (MARKETING_DATE, 0, 4) = '2018'
       --AND GROUP_NAME = '건설기술용역공제조합' 
     )
START WITH RNUM = 1
CONNECT BY PRIOR RNUM = RNUM - 1 AND PRIOR GROUP_NAME = GROUP_NAME
GROUP BY GROUP_NAME
ORDER BY GROUP_NAME ASC

 

출처 - http://blog.naver.com/PostView.nhn?blogId=jaejin1028&logNo=220793468335 

 

[MSSQL]일별,주별,월별 통계

Database 2010.06.29 23:14 Posted by 애플자라

-- 일단위
Select DATEPART(dd, order_dt), count(order_no) From 주문테이블
group by DATEPART(dd, order_dt)
order by DATEPART(dd, order_dt)

 

-- 주 단위
Select DATEPART(ww, order_dt), count(order_no) From 주문테이블
group by DATEPART(ww, order_dt)
order by DATEPART(ww, order_dt)

 

-- 월단위
Select DATEPART(mm, order_dt), count(order_no) From 주문테이블
group by DATEPART(mm, order_dt)
order by DATEPART(mm, order_dt)

 

-- 년단위
Select DATEPART(yy, order_dt), count(order_no) From 주문테이블
group by DATEPART(yy, order_dt)
order by DATEPART(yy, order_dt)


--분기별
SELECT A.memyear,A.AA,SUM(A.CNT) AS CNT
FROM (
Select DATEPART(yy, regdate) as memyear,DATEPART(mm, regdate) as memmonth,  count(regdate) as cnt
,(CASE DATEPART(mm, regdate) WHEN '1' THEN '1' WHEN '2' THEN '1' WHEN '3' THEN '1'
WHEN '4' THEN '2' WHEN '5' THEN '2' WHEN '6' THEN '2'
WHEN '7' THEN '3' WHEN '8' THEN '3' WHEN '9' THEN '3'
WHEN '10' THEN '4'
WHEN '11' THEN '4'
WHEN '12' THEN '4' ELSE '0' END) AS AA
From SMEM01MEM
group by DATEPART(mm, regdate),DATEPART(yy, regdate)
--order by DATEPART(ww, regdate)
) A
group by A.memyear,A.AA
order by A.memyear,A.AA

'Database' 카테고리의 다른 글

IBM DB2에서 select and update,delete 하기  (0) 2010.07.19
[MSSQL] MSSQL2000 ->2005 마이그레이션 attach  (0) 2010.07.05
[MSSQL]일별,주별,월별 통계  (0) 2010.06.29
MSSQL 데이터 백업  (0) 2010.06.07
Oracle DELETE_TRIGGER  (0) 2010.05.31
Oracle 짝수,홀수 구별  (0) 2010.05.26