溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

sql server訂單用戶復(fù)購問題怎么解決

發(fā)布時間:2022-05-31 11:09:10 來源:億速云 閱讀:197 作者:iii 欄目:大數(shù)據(jù)

這篇文章主要介紹了sql server訂單用戶復(fù)購問題怎么解決的相關(guān)知識,內(nèi)容詳細(xì)易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇sql server訂單用戶復(fù)購問題怎么解決文章都會有所收獲,下面我們一起來看看吧。

運(yùn)營需求拆解:

單一復(fù)購率公式(按周計(jì)算,需要計(jì)算從4.1-8.4的數(shù)據(jù)):

分子:本周和上周對同一商戶都下過單的人數(shù)

分母:上周下過訂單的總?cè)藬?shù)

注:需要考慮到可疑訂單,即刷單的狀況

需求拆解:難點(diǎn)在與分子計(jì)算;

需求進(jìn)一步拆解:本周和上周對同同一商戶下過單,則可以理解為用戶的復(fù)購;

可以把用戶和商戶 看成是一組,計(jì)算他們的復(fù)購即可;

具體代碼如下:

with tmp_weekly_user_god as (
   select
   concat(to_char(DATEADD(trade_date,-WEEKDAY(trade_date),'dd'),'yyyymmdd')
   ,'~' ,to_char(DATEADD(trade_date,6-WEEKDAY(trade_date),'dd'),'yyyymmdd'))  as  weekly_range
   ,weekofyear(trade_date) as weekly
   ,weekofyear(trade_date)+ 1 as next_weekly
   ,from_user_id
   ,to_user_id
   ,concat('-',from_user_id,to_user_id) as group_group  -- 組合
   from ypp_trade_flow
   where trade_type = 'ORDER' -- 交易訂單
   And TO_CHAR(trade_date,'yyyymmdd')  between  '20190401' and '20190804'
   group by concat(to_char(DATEADD(trade_date,-WEEKDAY(trade_date),'dd'),'yyyymmdd')
   ,'~' ,to_char(DATEADD(trade_date,6-WEEKDAY(trade_date),'dd'),'yyyymmdd'))  
   ,from_user_id
   ,to_user_id
   ,weekofyear(trade_date)
)

-- 留存率計(jì)算

select
t1.weekly  `周`
,t1.weekly_range `周維度`
,'全部' as `類型`
,count(distinct t1.from_user_id) as `純用戶下單人數(shù)`
,count(distinct t1.group_group) as `一組下單人數(shù)`
,count(distinct t2.group_group) as `一組本周用戶大神在上周繼續(xù)下單人數(shù)`
--,concat('',round(count(distinct t1.group_group)/count(distinct t2.group_group),4)*100,'%') as `單一復(fù)購率公式`
from tmp_weekly_user_god t1
left join tmp_weekly_user_god t2
on t1.group_group = t2.group_group
and t1.weekly = t2.next_weekly
group by t1.weekly,t1.weekly_range

結(jié)果集如下:


sql server訂單用戶復(fù)購問題怎么解決

細(xì)節(jié)問題:

  • 周維度:如果只使用weekofyear 只是給了一個具體的數(shù)字,而不清楚具體的周開始時間和結(jié)束時間,因此可以加上,更直觀,起代碼如下:

concat(to_char(DATEADD(trade_date,-WEEKDAY(trade_date),'dd'),'yyyymmdd'),'~' ,to_char(DATEADD(trade_date,6-WEEKDAY(trade_date),'dd'),'yyyymmdd'))

拆分下

周開始時間:`to_char(DATEADD(trade_date,-WEEKDAY(trade_date),'dd'),'yyyymmdd')

周結(jié)束時間:to_char(DATEADD(trade_date,6-WEEKDAY(trade_date),'dd'),'yyyymmdd')

  • 運(yùn)營的需求,細(xì)節(jié)還是有一點(diǎn)點(diǎn)問題,有沒有發(fā)現(xiàn),這個后續(xù)和運(yùn)營溝通解決了;

關(guān)于“sql server訂單用戶復(fù)購問題怎么解決”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對“sql server訂單用戶復(fù)購問題怎么解決”知識都有一定的了解,大家如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI