我可能误解了你的问题,但让我们看看,可从factOrder只,老式的方式客户的行为来学习。
假设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 ;
另一个忽略提及的项目是需要多对多关系的数量。例如,我将具有订单日期和订单地理的维度。这两者都必须是多对多的,因为每个客户可以下多个订单,并且每个订单都可以交付到不同的地点。事实上,我的几乎所有维度都是多对多的。 这是否会改变您对我的方法智慧的评估? – 2010-07-19 04:16:59
@凯文一个事实只能与一个维度相联系。如果客户有多个订单,“订单”不能成为客户的维度。从客户到订单有一张桥牌桌是毫无意义的 - 因为那个人必须将两个明星(客户和订单)连接到他们的业务密钥上。同上地理。不可能询问客户的“多地理区域”。订单的位置和数量以及平均订单数量都是可以询问客户的事情。看看你提出的尺寸 - 其中大部分对于顾客而言是毫无意义的。 – 2010-07-19 12:10:28
@Kevin例如:2010年1月1日起,客户C的产品计数地理位置是什么?问这个问题没有意义。客户有这样的事实,但地理不是事实的有效维度。 – 2010-07-19 12:12:06