【发布时间】:2020-05-16 11:20:14
【问题描述】:
我的数据记录是这样的
category dt userid amt
1 4/14/2019 1 140
1 5/1/2019 1 500
2 5/5/2019 1 300
3 5/19/2019 1 230
2 6/17/2019 1 200
4 6/18/2019 1 400
1 7/30/2019 1 400
1 8/17/2019 1 300
2 12/2/2019 1 200
2 12/23/2019 1 500
1 1/10/2019 2 470
1 2/25/2019 2 450
2 10/4/2019 2 350
Q1:如何计算每年每月的平均金额?
user month1 month2 month3 month4 month5 month6 month7 month8 month9 month10 month11 month12 avg_all_month
1 0 0 0 140 343.33 300 400 300 0 0 0 350 305.55
2 470 450 0 0 0 0 0 0 0 350 0 0 423.33
Q2:如何统计每个类别的交易
user pro_cat1 pro_cat2 pro_cat3 pro_cat4 total_product
1 4 3 1 1 7
2 2 1 0 0 3
【问题讨论】: