[ORACLE]ROW_NUMBER 순서

Database 2018.07.03 08:29 Posted by 애플자라
SELECT 
   ROW_NUMBER() OVER (ORDER BY NAME ASC) AS EMS_M_ID,
   NAME AS EMS_M_NAME,
   TRIM(REPLACE(MOBILE,'-','')) AS EMS_M_PHONE
FROM APLUSORA.TEMP_N_BOARD_EVENT
ORDER BY NAME ASC

 

'Database' 카테고리의 다른 글

[ORACLE]ROW_NUMBER 순서  (0) 2018.07.03
[Oracle] 누적접수건수  (0) 2018.06.27
[Oracle] 다중 LIKE(REGEXP_LIKE)  (0) 2018.06.12
[ORACLE]COUNT DECODE  (0) 2018.06.04
[ORACLE]WMSYS.WM_CONCAT 월별데이터 합치기  (0) 2018.04.06
[ORACLE]그룹함수로 중복된 컬럼 제거하기  (0) 2017.11.08

[Oracle] 누적접수건수

Database 2018.06.27 17:41 Posted by 애플자라

SELECT TO_CHAR (REG_DATE, 'YYYY-MM-DD') AS "접수일",
   COUNT (1) "접수건수",
   SUM (COUNT (1)) OVER (ORDER BY TO_CHAR (REG_DATE, 'YYYY-MM-DD')) "누적접수건수"
FROM N_BOARD_EVENT
GROUP BY TO_CHAR (REG_DATE, 'YYYY-MM-DD')
ORDER BY TO_CHAR (REG_DATE, 'YYYY-MM-DD')

 

'Database' 카테고리의 다른 글

[ORACLE]ROW_NUMBER 순서  (0) 2018.07.03
[Oracle] 누적접수건수  (0) 2018.06.27
[Oracle] 다중 LIKE(REGEXP_LIKE)  (0) 2018.06.12
[ORACLE]COUNT DECODE  (0) 2018.06.04
[ORACLE]WMSYS.WM_CONCAT 월별데이터 합치기  (0) 2018.04.06
[ORACLE]그룹함수로 중복된 컬럼 제거하기  (0) 2017.11.08

[Oracle] 다중 LIKE(REGEXP_LIKE)

Database 2018.06.12 08:13 Posted by 애플자라
EDIT EM_MMT_LOG_201806
WHERE TRAN_ETC2='MASS'
AND REGEXP_LIKE(TRAN_ETC1, '2018060800001|2018061100001|2018061100002')
--AND TRAN_ETC1 (LIKE '%2018060800001%' or LIKE '%2018061100001%' or LIKE '%2018061100002%')

 

'Database' 카테고리의 다른 글

[ORACLE]ROW_NUMBER 순서  (0) 2018.07.03
[Oracle] 누적접수건수  (0) 2018.06.27
[Oracle] 다중 LIKE(REGEXP_LIKE)  (0) 2018.06.12
[ORACLE]COUNT DECODE  (0) 2018.06.04
[ORACLE]WMSYS.WM_CONCAT 월별데이터 합치기  (0) 2018.04.06
[ORACLE]그룹함수로 중복된 컬럼 제거하기  (0) 2017.11.08

[ORACLE]COUNT DECODE

Database 2018.06.04 09:23 Posted by 애플자라

SELECT '신청: '||TOTAL||'건(전체), '||P_TYPE||'건(PC), '||M_TYPE||'건(모바일)' AS EVENT_M

FROM

(

SELECT COUNT (1) AS TOTAL,

       COUNT (DECODE (TYPE, 'P', 'P')) AS P_TYPE,

       COUNT (DECODE (TYPE, 'M', 'M')) AS M_TYPE

  FROM N_BOARD_EVENT

)

[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 

 

[ORACLE]그룹함수로 중복된 컬럼 제거하기

Database 2017.11.08 15:16 Posted by 애플자라

-- 2건이상 데이터
SELECT  MAX(ID) AS ID, MAX(TIMS_DATE) AS TIMS_DATE, MAX(FUND_CODE) AS FUND_CODE, COUNT(*) AS CNT
  FROM IFT_FUND_STANDARD_MODIFY
  WHERE FUND_CODE ='01032'
GROUP BY TIMS_DATE||FUND_CODE
HAVING COUNT(*) > 1

 

-- 2건이상 데이터중 과거 데이터 삭제
DELETE  -- SELECT꼭 해보고 날려버린다
FROM IFT_FUND_STANDARD_MODIFY
WHERE TIMS_DATE||FUND_CODE
IN
(
    SELECT TIMS_DATE||FUND_CODE
    FROM IFT_FUND_STANDARD_MODIFY
    WHERE FUND_CODE ='01032'
    GROUP BY TIMS_DATE||FUND_CODE
    HAVING COUNT(*) > 1
)
AND ID NOT IN (
SELECT  MAX(ID) as ID
  FROM IFT_FUND_STANDARD_MODIFY
  WHERE FUND_CODE ='01032'
GROUP BY TIMS_DATE||FUND_CODE
HAVING COUNT(*) > 1
)

 

CONCAT(TIMS_DATE,FUND_CODE) 도 가능

 

출처 - http://linguist79.tistory.com/49

--  1,2 컬럼값이 서로 같고 3컬럼값만 다른경우
SELECT * FROM A, B
WHERE (A.1 = B.1 AND A.2 = B.2)
AND A.3 <> B.3;

--  1,3컬럼값은 같고  2컬럼값만 다른 경우
SELECT * FROM A, B
WHERE (A.1 = B.1 AND A.3 = B.3)
AND A.2 <> B.2;

--  2,3컬럼값은 같고  1컬럼값만 다른 경우
SELECT * FROM A, B
WHERE (A.2 = B.2 AND A.3 = B.3)
AND A.1 <> B.1;


--  1,2,3 컬럼이 전부 다른 경우
SELECT * FROM A, B
WHERE A.1 <> B.1 AND A.2 <> B.2
AND A.3 <> B.3;

 

출처 - http://www.gurubee.net/article/59245

 

--------------------------------------------------------

 

SELECT A.TIMS_DATE,
       A.FUND_CODE,
       A.FUND_NAME,
       A.BM_INDEX,
       B.BM_INDEX,
       A.BM_RATE,
       B.BM_RATE
  FROM IFT_FUND_STANDARD_PRICE_RESULT A, IFT_FUND_STANDARD_MODIFY B
 WHERE     (A.BM_INDEX <> B.BM_INDEX OR A.BM_RATE <> B.BM_RATE)
       --AND A.TIMS_DATE = '20171104'
       AND A.TIMS_DATE = TO_CHAR(SYSDATE-3, 'YYYYMMDD')
       AND A.TIMS_DATE = B.TIMS_DATE
       AND A.FUND_CODE = B.FUND_CODE

[ORACLE]ALTER COLUMN

Database 2017.10.17 08:34 Posted by 애플자라

-- 일반 컬럼수정
ALTER TABLE EM_MMT_TRAN
MODIFY RECIPIENT_NUM VARCHAR2(16 BYTE)

 

-------------------------------------------------------------------------------------


-- 일반 컬럼수정(NOT NULL)
-- ORA-01442: column to be modified to NOT NULL is already NOT NULL
ALTER TABLE EM_MMT_TRAN
MODIFY CALLBACK VARCHAR2(16 BYTE) NOT NULL

 

-- DISABLE
ALTER TABLE EM_MMT_TRAN DISABLE CONSTRAINT SYS_C0037363 CASCADE

 

--> 일반 컬럼 수정문 실행

 

-- ENABLE
ALTER TABLE EM_MMT_TRAN ENABLE CONSTRAINT SYS_C0037363 

 

SYS_C0037363 Check    Enabled        Not Deferrable    Immediate    Validated            1    "CALLBACK" IS NOT NULL

 

SELECT
 운용사펀드코드,
 (SELECT 설정일 FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 12.0;Database=D:\20170703\설정일생성.xlsx;','SELECT * FROM [Sheet1$]') WHERE 펀드코드 = A.운용사펀드코드) AS 설정일
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 12.0;Database=D:\20170703\펀드설정전체.xlsx;','SELECT * FROM [Sheet1$]') A

----------------------------------------------- 기본셋팅

1. Ad Hoc Distributed Queries 옵션 활성화

EXEC sp_configure 'show advanced options', 1

GO

 

RECONFIGURE

GO

 

EXEC sp_configure 'Ad Hoc Distributed Queries', 1

GO

 

RECONFIGURE

GO

2. Mirosoft Access Database Engine 2010 Redistributable  설치

http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=13255

자 이제 준비는 다 되었다. 이제 쿼리로 엑셀을 테이블처럼 사용하면 된다.


출처 - http://yoonsy.tistory.com/12

[MYSQL]원격지 SELECT

Database 2017.02.07 08:29 Posted by 애플자라

CREATE TABLE `tb_result_117` (
  `STAND_DATE` varchar(8) NOT NULL COMMENT '작업일자',
  `ITEM_CD` char(12) NOT NULL COMMENT '배치작업의 코드',
  `SUB_SECTION` varchar(32) NOT NULL COMMENT '배치작업의 코드 하부 작업(하부분류또는 파일명)',
  `START_TIME` varchar(6) NOT NULL COMMENT '시작시간',
  `END_TIME` varchar(6) DEFAULT NULL COMMENT '마감시간',
  `RESULT_MESSAGE` varchar(512) DEFAULT NULL COMMENT '처리결과 메시지',
  `TOTAL_COUNT` int(11) DEFAULT NULL COMMENT '전체건수',
  `PROCESSED_COUNT` int(11) DEFAULT NULL COMMENT '처리건수',
  `PROCESS_NAME` varchar(50) DEFAULT NULL,
  `SEND_DATE` datetime DEFAULT NULL,
  `FLAG` char(1) CHARACTER SET latin1 DEFAULT 'N',
  PRIMARY KEY (`STAND_DATE`,`ITEM_CD`,`SUB_SECTION`,`START_TIME`)
) ENGINE=FEDERATED DEFAULT CHARSET=utf8 COMMENT='일별 배치' CONNECTION='mysql://DBID:DB패스워드@DBIP:포트/dg_db_batch/tb_result';

 

참고 - http://itzone.tistory.com/672