-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisc1.sql
More file actions
29 lines (28 loc) · 956 Bytes
/
misc1.sql
File metadata and controls
29 lines (28 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
select (mu1 - mu2)/power(var1/n1 + var2/n2, 0.5) t_stat
from
(select
sum(case when other_id = 'Yes' then mu else 0 end) as mu1,
sum(case when other_id = 'No' then mu else 0 end) as mu2,
sum(case when other_id = 'Yes' then var else 0 end) as var1,
sum(case when other_id = 'No' then var else 0 end) as var2,
sum(case when other_id = 'Yes' then n else 0 end) as n1,
sum(case when other_id = 'No' then n else 0 end) as n2
from
(select other_id,
avg(num_trans) mu,
avg(power(num_trans, 2)) - power(avg(num_trans), 2) var,
count(num_trans) n
from
(select user_id,
case
when other_id = 'No' then 'No'
else 'Yes' end as other_id,
num_trans from
(select t1.user_id, ifnull(t2.user_id, 'No') other_id,
count(ifnull(t2.user_id, 'No')) num_trans
from transactions t1
left join (select distinct user_id from events) t2
on t1.user_id = t2.user_id
group by t1.user_id, ifnull(t2.user_id, 'No')) t) t
group by other_id) t) t
/*t-stat suggests no statistical difference*/