私はあなたの質問を誤解しているかもしれませんが、昔ながらの方法であるfactOrder onlyから顧客の行動について何が学べるか見てみましょう。
factOrder の粒度が注文の 1 行であり、縮退ディメンションとしてOrderIDがあると仮定します。
-- Number of customers who ordered something at least once
select
count(distinct CustomerKey) as PayingCustomers
from factOrder ;
.
-- Number of orders and sales per customer
select
CustomerKey
, count(distinct OrderID) as NumberOfOrders
, sum(ExtendedPrice) as Total
from factOrder
group by CustomerKey ;
.
-- Histogram (x = NumberOfOrders, y = People, Amount)
with
orders_per_customer as (
select
CustomerKey
, count(distinct OrderID) as cnt
, sum(ExtendedPrice) as Total
from factOrder
group by CustomerKey
)
select
cnt as NumberOfOrders
, count(1) as People
, sum(Total) as Amount
from orders_per_customer
group by cnt
order by cnt asc ;
.
-- Distinct products ordered by customer
select
CustomerKey
, count(distinct ProductKey) as DistinctProductsOrdered
from factOrder
group by CustomerKey ;
.
-- Histogram (x = NumberOfDistinctProducts, y = People)
with
products_per_customer as (
select
CustomerKey
, count(distinct ProductKey) as cnt
from factOrder
group by CustomerKey
)
select
cnt as NumberOfDistinctProducts
, count(1) as People
from products_per_customer
group by cnt
order by cnt asc ;