私は昨夜、この問題についていくつかの調査を行い、神の恵みにより、あなた (OK、あなたのビジネス パートナー) がバケット サイズを定義し、配布頻度カウントをカウントできる解決策を見つけました。
ここにあります -- (この Web サイトの形式が下手で申し訳ありません) ご協力ありがとうございました!! アレックス
with starter as(
select cust.customer_id, count(o.order_id) as row_count
from CUSTOMER cust LEFT JOIN ORDER o
using (customer_id)
where cust.last_update_user = 'MDM_ETL' and
o.last_update_user = 'MDM_ETL' -- and
group by cust.customer_id
order by row_count desc)
select 5 , '2000 or more' as cnt_of_orders, count(starter.customer_id) as
nmb_customers_with_this_cnt from starter where starter.row_count >= 2000
union
select 4, '1500 - 1999' as cnt_of_orders, count(starter.customer_id) as
nmb_customers_with_this_cnt from starter where starter.row_count between 1500 and 1999
union
select 3, '1000 - 1499' as cnt_of_orders, count(starter.customer_id) as
nmb_customers_with_this_cnt from starter where starter.row_count between 1000 and 1499
union
select 2, '500 - 999' as cnt_of_orders, count(starter.customer_id) as
nmb_customers_with_this_cnt from starter where starter.row_count between 500 and 999
union
select 1, '0 - 499' as cnt_of_orders, count(starter.customer_id) as
nmb_customers_with_this_cnt from starter where starter.row_count between 0 and 499