我可能誤解了你的問題,但讓我們看看,可從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