我可能误解了您的问题,但让我们看看可以从factOrder only(老式的方式)中了解哪些客户行为。
假设 factOrder 的粒度是订单上的一行,并且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 ;