[DB]SQLP-2の実行


累計売上高を求める

  • 支店、販売月、販売月を列挙した表の毎月累計販売
    ウィンドウの関数で求めて、求めないでください
    select 지점, 판매월, 매출,
    sum(매출) over(partition by 지점 order by 판매월)
    from table
    select a.지점, a.판매월, a.매출, sum(b.매출)
    from table a, table b
    where a.지점 = b.지점
    and a.판매월 >= b.판매월
    group by a.지점, a.판매월, a.매출
    order by a.지점, a.판매월
     
  • 実2索引、結合調整
    create index 주문 on idx_01(고객번호, 주문일시) local
    create index 고객 on idx_02(거주지역코드, 고객명)
    
    select /*+ leading(c) use_nl(o) index(c idx_02) index(o idx_01)*/
    o.주문일시, o.주문번호 . . . . 
    from 고객 c, 주문 o
    where (c.거주지역코드 = 02 and c.고객명 = 김철수)
    or    (c.거주지역코드 = 05 and c.고객명 = 홍길동)
    and o.고객번호 = c.고객번호
    and o.주문실시 between to_date('20150301', 'yyyymmdd')
    and to_date('20150314235959', 'yyyymmddhh24miss')
    order by o.주문일시, c.고개명
  • パーティションテーブルインデックス定義を考慮したパーティションインデックス
  • の結合順序および方式
  • を正しく説明する.
    アプリケーション
  • インデックス
  • 未加工居住区コードと顧客名であるが、条件は
  • であることが明確である.
    検索条件はあってもなくてもよい
    create index table on index_01(고객번호, 주문일자);
    create index table on index_02(주문일자);
    
    select /*+index(a index_01)*/ 고객번호, 주문일시, . .
    from 주문 a
    where :cusid is not null
    and 고객번호 = :cusid 
    and 주문일자 >= to_date(:dt1, 'yyyymmdd')
    and 주문일자 < to_date(:dt2, 'yyyymmdd')+1
    union all
    select /*+index(b index2)*/ 고객번호, 주문일시 . . .
    from 주문 b
    where :cusid is null
    and 주문일자 >= to_date(:dt1, 'yyyymmdd')
    and 주문일자 < to_date(:dt2, 'yyyymmdd')+1
    order by 주문일자 desc;
  • は、顧客番号がある場合もあれば、顧客番号がない場合もあるため、常に最適な計画応答
  • である.
  • インデックスに対応する2つの
  • が作成されます.
    2つの
  • クエリー文を作成し、union all応答
  • として使用します.
  • ソートは常に最後の
  • オーダー日は日付形式で、intervalを使用して時間まで記入しなければならないが、入力値はSTRINGであるため、日付と不等号を
  • に容易に処理することができる.
    ページング処理、最近の接続が一時的に存在しない場合null
    create index 고객 on idx_01(고객상태코드, 등록일자, 고객번호);
    create index 고객접속이력 on idx_02(고객번호, 접속일시);
    
    select t1.고객번호, t1.고객명, t1.등록일시,
            (select /*+고객접속이력 IDX_02*/max(접속일시)
             from 고객접속이력
             where 고객번호 = t1.고객번호
             and 접속일자 >= trunc(add_month(sysdate, -1))) 최근접속일시
    from  (select t1.*, rownum as rown
           from  (select /*+고객 IDX_01 */고객번호, 고객명, 등록일시
                  from 고객
                  where 고객상태코드='AC'
                  order by 등록일시, 고객번호) t1
           where rownum <= :page1*20) t1
    where rown > (:page1 -1) * 20 
    
  • は、選択性の良い顧客ステータスコードを使用して、最も少ない顧客をもたらします.
  • ROWNUMと不等式で総ページをインポートし、再加工して20個のみインポートします.
  • 最近登録した時は、LEFTOUTER接続よりスカラーで検索するのが好きでした.
  • インデックスは、クライアント・テーブルのソート操作を排除します.
  • すべてのコミュニケーションステータスを表示するお客様
    select /*+ leading(a b) full(a) use_hash(b) */
    a.고객번호, a.고객명, a.폰번, b.최근고객접속일자
    from 고객 a left outer join 
         (select /*+NO_MERGE*/고객번호, max(고객접속일자) 최근고객접속일자
         from 고객접속이력
         where 고객접속일자 >= add_months(sysdate, -1)
         group by 고객번호) b
     on a.고객번호 = b.고객번호 
     where a.고객상태코드 = 'AC'
    order by a.고객번호, a.고객명
  • all rowsクエリー、適切な完全スキャンとハッシュ結合
  • を使用
  • swap join inputs等のハッシュ結合の生成インバウンド調整(現在はプリアンブルとして指定)
  • のオンラインビューでは、まず、最近の顧客接続が空ではない(顧客接続日>=add month(sysdate、-1)を満たすデータを検索し、グループ化します.
  • ビューの摩耗を防止するために、no mergeヒント.
  • 左外部接続
  • のため、最近の接続日が1ヶ月を超えたお客様はnullに変換されます.