分析の過程で、特徴のクォンタイルを計算する必要があることがよくあります。Oracleでデータの特定の列のクォンタイルを計算する方法は次のとおりです。
クォンタイルを必要とするテーブルの構造は次のとおりです。
select * from test_lizhen;
テーブルには2つの列があり、1つの列は異なる製品を表し、もう1つの列は各ユーザーの属性を表すことがわかりました。次の方法で特徴のクォンタイルを計算できます
1)製品に関係なく、すべてのユーザーのクォンタイルを計算します
select PERCENTILE_CONT(0) within group(order by pltf_cnt_60m) as max_sal_0,
PERCENTILE_CONT(0.2) within group(order by pltf_cnt_60m) as max_sal_20,
PERCENTILE_CONT(0.4) within group(order by pltf_cnt_60m) as max_sal_40,
PERCENTILE_CONT(0.6) within group(order by pltf_cnt_60m) as max_sal_60,
PERCENTILE_CONT(0.8) within group(order by pltf_cnt_60m) as max_sal_80,
PERCENTILE_CONT(1) within group(order by pltf_cnt_60m) as max_sal_100
from test_lizhen;
結果は次のとおりです。
2)製品を区別し、異なる製品のユーザーの量を計算します
select distinct product_no,
PERCENTILE_CONT(0) within group(order by pltf_cnt_60m) over(partition by product_no) max_sal_0,
PERCENTILE_CONT(0.2) within group(order by pltf_cnt_60m) over(partition by product_no) max_sal_0,
PERCENTILE_CONT(0.4) within group(order by pltf_cnt_60m) over(partition by product_no) max_sal_0,
PERCENTILE_CONT(0.6) within group(order by pltf_cnt_60m) over(partition by product_no) max_sal_0,
PERCENTILE_CONT(0.8) within group(order by pltf_cnt_60m) over(partition by product_no) max_sal_0,
PERCENTILE_CONT(1) within group(order by pltf_cnt_60m) over(partition by product_no) max_sal_0
from test_lizhen;
結果は次のとおりです。
特定のユーザーの変数の全体的な位置を計算することもできます。
PERCENT_RANK() over(partition by product_no order by pltf_cnt_60m) p_rank