https://gregorio78.tistory.com/98

 

Oracle Hint 종류 및 설명

[Optimization Approaches and Goals - Optimization 접근과 목적] /*+ ALL_ROWS */설명 : 가장 좋은 단위 처리량의 목표로 문 블록을 최적화하기 위해 cost-based 방법을 선택합니다. (즉, 전체적인 최소의 자원 소비)

gregorio78.tistory.com

 

728x90

'Database > Oracle' 카테고리의 다른 글

Oracle XE 다운로드 (무료버전)  (0) 2023.05.30
Oracle 중간값 계산하기  (0) 2023.04.25
오라클 테이블 명세생성 조회 쿼리  (0) 2022.08.17
오라클 버전 확인 쿼리  (0) 2022.08.17
subtotal,cube,grouping_id  (0) 2021.04.01

 

https://www.oracle.com/kr/database/technologies/appdev/xe.html

 

Oracle Database Express Edition | Oracle 대한민국

모두를 위한 무료 Oracle Database 개발자, DBA, 데이터 과학자, 교육자 등 데이터베이스를 탐구하는 모두에게 Oracle Database Express Edition(XE)은 데이터베이스 입문에 매우 이상적인 방법입니다. Oracle Datab

www.oracle.com

end.

 

728x90

'Database > Oracle' 카테고리의 다른 글

참조 index 소개  (1) 2023.10.12
Oracle 중간값 계산하기  (0) 2023.04.25
오라클 테이블 명세생성 조회 쿼리  (0) 2022.08.17
오라클 버전 확인 쿼리  (0) 2022.08.17
subtotal,cube,grouping_id  (0) 2021.04.01

Oralce 및 기타 여러 DB에서 중앙값 함수를 제공하지 않아서 로직 샘플 짬.

WITH GOODS AS (
          SELECT 'A' AS GOOD_NM, 'SELLER_1' AS SELLER, 110 AS PRICE_MIN, 310 AS PRICE_MAX FROM DUAL
UNION ALL SELECT 'A' AS GOOD_NM, 'SELLER_2' AS SELLER, 120 AS PRICE_MIN, 330 AS PRICE_MAX FROM DUAL
UNION ALL SELECT 'A' AS GOOD_NM, 'SELLER_3' AS SELLER, 130 AS PRICE_MIN, 320 AS PRICE_MAX FROM DUAL
UNION ALL SELECT 'A' AS GOOD_NM, 'SELLER_4' AS SELLER, 140 AS PRICE_MIN, 340 AS PRICE_MAX FROM DUAL
UNION ALL SELECT 'A' AS GOOD_NM, 'SELLER_5' AS SELLER, 150 AS PRICE_MIN, 350 AS PRICE_MAX FROM DUAL
UNION ALL SELECT 'B' AS GOOD_NM, 'SELLER_1' AS SELLER, 210 AS PRICE_MIN, 460 AS PRICE_MAX FROM DUAL
UNION ALL SELECT 'B' AS GOOD_NM, 'SELLER_2' AS SELLER, 220 AS PRICE_MIN, 410 AS PRICE_MAX FROM DUAL
UNION ALL SELECT 'B' AS GOOD_NM, 'SELLER_3' AS SELLER, 230 AS PRICE_MIN, 420 AS PRICE_MAX FROM DUAL
UNION ALL SELECT 'B' AS GOOD_NM, 'SELLER_4' AS SELLER, 240 AS PRICE_MIN, 450 AS PRICE_MAX FROM DUAL
UNION ALL SELECT 'B' AS GOOD_NM, 'SELLER_5' AS SELLER, 250 AS PRICE_MIN, 430 AS PRICE_MAX FROM DUAL
UNION ALL SELECT 'B' AS GOOD_NM, 'SELLER_6' AS SELLER, 260 AS PRICE_MIN, 440 AS PRICE_MAX FROM DUAL
) 
SELECT GOOD_NM
     , SUM(CASE WHEN MOD(GROUP_CNT, 2) <> 0 AND PRICE_MIN_SEQ = (TRUNC(GROUP_CNT/2) + 1)                THEN PRICE_MIN -- 홀수계산. 중앙값 계산
                WHEN MOD(GROUP_CNT, 2) =  0 AND PRICE_MIN_SEQ BETWEEN GROUP_CNT/2 AND (GROUP_CNT/2 + 1) THEN PRICE_MIN -- 짝수계산
               END) 
     / SUM(CASE WHEN MOD(GROUP_CNT, 2) <> 0 AND PRICE_MIN_SEQ = (TRUNC(GROUP_CNT/2) + 1)                THEN 1
                WHEN MOD(GROUP_CNT, 2) =  0 AND PRICE_MIN_SEQ BETWEEN GROUP_CNT/2 AND (GROUP_CNT/2 + 1) THEN 1
                END) AS PRICE_MIN_MEAN
     , SUM(CASE WHEN MOD(GROUP_CNT, 2) <> 0 AND PRICE_MAX_SEQ = (TRUNC(GROUP_CNT/2) + 1)                THEN PRICE_MAX -- 홀수계산. 중앙값 계산
                WHEN MOD(GROUP_CNT, 2) =  0 AND PRICE_MAX_SEQ BETWEEN GROUP_CNT/2 AND (GROUP_CNT/2 + 1) THEN PRICE_MAX -- 짝수계산
               END) 
     / SUM(CASE WHEN MOD(GROUP_CNT, 2) <> 0 AND PRICE_MAX_SEQ = (TRUNC(GROUP_CNT/2) + 1)                THEN 1
                WHEN MOD(GROUP_CNT, 2) =  0 AND PRICE_MAX_SEQ BETWEEN GROUP_CNT/2 AND (GROUP_CNT/2 + 1) THEN 1
                END) AS PRICE_MAX_MEAN
  FROM (
      SELECT A.*
           , ROW_NUMBER() OVER(PARTITION BY GOOD_NM ORDER BY PRICE_MIN) AS PRICE_MIN_SEQ
           , ROW_NUMBER() OVER(PARTITION BY GOOD_NM ORDER BY PRICE_MAX) AS PRICE_MAX_SEQ
           , COUNT(*)     OVER(PARTITION BY GOOD_NM)                    AS GROUP_CNT
        FROM GOODS A
       ) A
GROUP BY GOOD_NM

| 결과

GOOD_NM PRICE_MIN_MEAN PRICE_MAX_MEAN
A 130 330
B 235 435

 

728x90

'Database > Oracle' 카테고리의 다른 글

참조 index 소개  (1) 2023.10.12
Oracle XE 다운로드 (무료버전)  (0) 2023.05.30
오라클 테이블 명세생성 조회 쿼리  (0) 2022.08.17
오라클 버전 확인 쿼리  (0) 2022.08.17
subtotal,cube,grouping_id  (0) 2021.04.01
SELECT TC.OWNER
     , TC.TABLE_NAME 
     , TC.COLUMN_NAME
     , TRANSLATE(CC.COMMENTS, CHR(10)||CHR(13), '.') AS COMMENTS
     , CASE WHEN TC.NULLABLE = 'N' THEN 'Y'
            ELSE 'N'
            END AS NOT_NULL
     , TC.DATA_TYPE
     , CASE WHEN TC.DATA_TYPE = 'NUMBER' AND TC.DATA_PRECISION IS NOT NULL THEN '' || TC.DATA_PRECISION || ',' || TC.DATA_SCALE || ''
            WHEN TC.DATA_TYPE LIKE '%CHAR%' THEN '' || TC.DATA_LENGTH || ''
            ELSE NULL
            END AS TYPE_SIZE
FROM  ALL_TAB_COLUMNS  TC
    , ALL_COL_COMMENTS CC
WHERE TC.OWNER = CC.OWNER
  AND TC.COLUMN_NAME = CC.COLUMN_NAME
  AND TC.TABLE_NAME = CC.TABLE_NAME 
--  AND TC.OWNER = '스키마명'
--  AND TC.TABLE_NAME = '테이블명'
ORDER BY TC.TABLE_NAME, TC.COLUMN_ID
728x90

'Database > Oracle' 카테고리의 다른 글

Oracle XE 다운로드 (무료버전)  (0) 2023.05.30
Oracle 중간값 계산하기  (0) 2023.04.25
오라클 버전 확인 쿼리  (0) 2022.08.17
subtotal,cube,grouping_id  (0) 2021.04.01
[Oracle] HR계정 사용하기  (0) 2019.12.29

+ Recent posts