Oralce字段排列組合計數

Oralce字段排列組合計數

  • 表結構
    create table app_impact_rule(
    c_app_id varchar2(64),
    ext_id varchar2(64),
    oc_app_id varchar2(64),
    rule_type varchar2(32)
    );

  • 查詢SQL
    with temp as
    (
    select t.c_app_id,t.rule_type, count(t.rule_type) over(partition by c_app_id) n_count
    from risk.app_impact_rule t
    where t.c_app_id is not null
    ),
    temp1 as(
    select listagg(rule_type,',') within GROUP (order by rule_type) t_type
    from temp
    where n_count>1
    group by n_count,C_APP_ID
    )
    select t_type 組合方式,
    count(t_type) 數量
    from temp1
    group by t_type
    order by length(t_type);

  • temp數據

    這裏寫圖片描述

  • temp1數據

    這裏寫圖片描述

  • 最終結果

    這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章