文章目录
销售数据文件链接(失效了可以在评论区艾特):
https://pan.baidu.com/s/1-thB0rrXYmkSoey30lwYLg 提取码:kmr8
使用mysql完成上面的6个问题。首先导入本地csv文件到mysql,有两种方式。第一种,直接导入,如下图所示:
注意:csv表要有表头,不然会导入不进去。
但是这种方式导入数据很慢,采取第二种方式,用代码导入很快
导入两个数据表order_info和user_info,其中order_info包含的信息如下:
user_info包含的信息如下:
问题1:统计不同月份的下单人数
select month(paidtime),count(distinct userid)
from order_info
where status !='未支付'
group by month(paidtime);
问题2.统计用户三月份的回购率和复购率
select userid,count(userid)
from order_info
where status ='已支付'
and month(paidtime)=3
group by userid;
先计算出3月份每个用户的购买次数,复购率就等于购买次数大于1的人数除以购买的总人数
select count(ct) '购买人数',
count(if(ct>1,1,null)) '回购人数' ,
count(if(ct>1,1,null)