select users.uid,
tran.event
from public.app_ok_cbaiodclebabababa_agg_users users
left join public.app_ok_CBAIODCLEBABABABA_agg_transactions tran
on users.uid=tran.uid
where first_event_time >= '2017-09-01 0:00:00'
and first_event_time <= '2017-09-11 0:00:00'
and tran.event = 'successful transaction'
在此查询中,我们选择用户id(uid)
,event
(交易事件是否成功)和2017-09-01 to 2017-09-11
的时间间隔(他注册时的日期)。
那么如何计算每个用户在一周内做出的交易数量?
决定
add this string AND datediff(day,first_event_time, event_time)<=7
谢谢,亲爱的朋友们
答案 0 :(得分:1)
如果没有看到你的数据,这很难,但看起来你似乎是在追求这样的事情;
SELECT
users.uid,
tran.event,
COUNT(tran.event) Event_Count
FROM public.app_ok_cbaiodclebabababa_agg_users users
LEFT JOIN public.app_ok_CBAIODCLEBABABABA_agg_transactions tran
ON users.uid=tran.uid
WHERE first_event_time >='2017-09-01 0:00:00'
AND first_event_time <= '2017-09-11 0:00:00'
AND tran.event='successful transaction'
GROUP BY users.uid,tran.event
这将计算tran.event中符合WHERE
子句
答案 1 :(得分:1)
select
COUNT(*),
first_event_time
from public.app_ok_cbaiodclebabababa_agg_users users
left join public.app_ok_CBAIODCLEBABABABA_agg_transactions tran on
users.uid=tran.uid
where first_event_time>='2017-09-01 0:00:00'
and first_event_time <= '2017-09-11 0:00:00'
and tran.event='successful transaction'
GROUP BY first_event_time
答案 2 :(得分:1)
您可以在用户ID上使用Group by
请试试这个:
select x.userId,count(*) NumberOfTransaction
(
select
users.uid userId,
tran.event tEvent
from public.app_ok_cbaiodclebabababa_agg_users users
left join public.app_ok_CBAIODCLEBABABABA_agg_transactions tran on
users.uid=tran.uid
where first_event_time>='2017-09-08 0:00:00'
and first_event_time <= '2017-09-15 0:00:00'
and tran.event='successful transaction'
) x
Group By x.userId
我希望这会有所帮助。
答案 3 :(得分:1)
我想你想要这样的东西:
select u.uid, sum(t.uid)
from public.app_ok_cbaiodclebabababa_agg_users u left join
public.app_ok_CBAIODCLEBABABABA_agg_transactions t
on u.uid = t.uid and
t.? >= '2017-09-08' and
t.? < '2017-09-16' and
t.event = 'successful transaction'
where first_event_time >= '2017-09-01' and
first_event_time < '2017-09-12';
您的问题不清楚哪个列用于活动时间。
另请注意,日期逻辑已更改。
答案 4 :(得分:0)
你可以尝试吼一声
选择
u.uid,
tn.event
来自用户你
左连接交易tn on
u.uid = tn.uid
其中tran.event ='成功交易'和'2017-09-01 0:00:00'和'2017-09-11 0:00:00'之间的first_event_time