已知兩張表,交易表order(ordercode訂單號、storecode門店號、customerID會員號、sales消費金額、buytime購買時間)
訂單產品關聯表product(ordercode訂單號、sku產品號、qty購買數量)
1 求2018年首購客戶在首購一個月內復購的人數
2 2018年的復購率及平均復購周期
uj5u.com熱心網友回復:
請問"2018年首購客戶"的定義是什么?uj5u.com熱心網友回復:
在2018年第一次購買uj5u.com熱心網友回復:
-- 1 求2018年首購客戶在首購一個月內復購的人數
select customerID=count(distinct a.customerID)
from [order] a
inner join (select customerID,
firstbuytime=min(buytime)
from [order]
group by customerID) b on a.customerID=b.customerID
where b.firstbuytime between '2018-01-01' and '2018-12-31'
and exists(select 1
from [order] c
where c.customerID=a.customerID
and c.buytime<=dateadd(m,1,b.firstbuytime))
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/77750.html
標籤:疑難問題
下一篇:有給搭建私人郵箱的嗎
