我正在尝试创建一个表格,其中平均销售额除以在某个月份注册帐户的一组用户,但是,我只能计算出除以在该月份进行购买的人数特定月份低于该群组的总金额。如何更改以下查询以使avg_sucessful_transacted
每个月的每个金额除以同类群组 0?
谢谢你。
select sum (t.amount_in_dollars)/ count (distinct u.id) as Avg_Successful_Transacted, (datediff(month,[u.created:month],[t.createdon:month])) as Cohort, [u.created:month] as Months,
count (distinct u.id) as Users
from [transaction_cache as t]
left join [user_cache as u] on t.owner = u.id
where t.type = 'savings' and t.status = 'successful' and [u.created:year] > ['2017-01-01':date:year]
group by cohort, months
order by Cohort, Months