用MySQL分析网络销售数据

数据来自某个销售网站的数据

1.网络订单数据

2.用户信息

点击获取数据     提取码:udek

分析步骤

0、数据导入

1、不同月份的下单人数

2、用户三月份的回购率和复购率

3、统计男女用户的消费频次

4、统计多次消费用户,分析第一次和最后一次的消费间隔

5、统计不同年龄段用户的消费金额差异

6、统计消费的二八法则:消费top20%的用户贡献了多少消费额度

0 数据导入

首先需要先创建对应的数据库和相应的表

1.创建orderinfo 表

2.创建userinfo表

3.使用navicat导入csv文件

4.登录mysql,观察数据,对时间进行处理 ; 更新字符串为日期格式

# 登录

mysql-uroot -p

# 时间进行处理,更新字符串为日期格式

update orderinfo set paidtime=replace(paidtime,'/','-') where paidtime is not null

update orderinfo set paidtime=str_to_date(paidtime,'%Y-%m-%d %H:%i') where paidtime is not null

5.查看数据

1 不同月份的下单人数

思路 :按月份进行分组,对用户进行去重统计

select month(paidTime) asdtmonth,count(distinct userId) ascount_usersfromorderinfowhere isPaid = '已支付'

group bydtmonth

2 用户三月份的回购率和复购率

复购率 : 自然月内,购买多次的用户占比

首先先找出已支付中3月份的用户id和对应次数,按用户分组

然后再嵌套一层,复购率:购买次数大于1/ 总购买次数

select count(ct),count(if(ct>1,1,null)) from(select userID,Count(userId) as ct fromorderinfowhere isPaid = '已支付'

and month(paidTime) = 3

group byuserIdorder by userId) t

复购率: 16916 / 54799 = 0.308

2.回购率: 曾经购买过的用户在某一时期内再次购买的占比

首先先查询已支付userId ,和 支付月份的统计

select userId, date_format(paidTime, '%Y-%m-01') as m fromorderinfowhere isPaid = '已支付'

group by userId , date_format(paidTime,'%Y-%m-01')

然后使用date_sub函数,将表关联,筛选出本月的消费的userID,和下月的回购userID,即可计算出回购率

select t1.m,count(t1.m) as消费总数,count(t2.m) as复购率,count(t2.m)/ count(t1.m) as 回购率 from(select userId, date_format(paidTime, '%Y-%m-01') as m fromorderinfowhere isPaid = '已支付'

group by userId , date_format(paidTime,'%Y-%m-01')) t1left join(select userId, date_format(paidTime, '%Y-%m-01') as m fromorderinfowhere isPaid = '已支付'

group by userId , date_format(paidTime,'%Y-%m-01')) t2on t1.userId = t2.userId and t1.m = date_sub(t2.m, interval 1 month)group by t1.m

3 统计男女用户的消费频次

userinfo因为性别有空值,需要筛选出t orderinfo 再和表t连接 统计出用户男女消费次数

select o.userId,sex,count(o.userId)as ct fromorderinfo oinner join(select * fromuserinfowhere sex != '') ton o.userId =t.userIdgroup byuserId,sexorder by userId

根据上表,在进行子查询,统计出男女消费平均频次

select sex,avg(ct) from(select o.userId,sex,count(o.userId)as ct fromorderinfo oinner join(select * fromuserinfowhere sex != '') ton o.userId =t.userIdgroup byuserId,sexorder byuserId)t2group by sex

4 统计多次消费用户,分析第一次和最后一次的消费间隔

首先把多次消费的用户,和相应第一次最后一次消费时间提取出来

然后使用datediff 计算时间间隔,以天为单位

select userId,max(paidTime),min(paidTime),datediff(max(paidTime),min(paidTime)) fromdata.orderinfowhere isPaid = '已支付'

group by userId having count(1) > 1

order by userId

5 统计不同年龄段用户的消费金额差异

通过表联结,给用户划分不同的年龄段,以10年为基准,过滤出生日期为1900-00-00的异常值,筛选出用户消费频次和消费金额

select o.userId,age,sum(price),count(o.userId)as ct fromorderinfo oinner join(select userId, ceil((year(now()) - year(birth))/10) asagefromuserinfowhere birth > 1901-00-00) ton o.userId =t.userIdwhere isPaid = '已支付'

group byuserIdorder by userId

统计出年龄段的消费频次和消费金额

select t2.age,avg(ct),avg(sp) from (

select o.userId,age,sum(price) as sp,count(o.userId)as ct from orderinfo o

inner join(

select userId, ceil((year(now()) - year(birth))/10) as age

from userinfo

where birth > 1901-00-00)t

on o.userId = t.userId

where ispaid = '已支付'

group by userId, age) t2

group by age

order by age

ceil : 向上取整

6 统计消费的二八法则:消费top20%的用户贡献了多少消费额度

按照用户消费总额排序

select userId,sum(price) as total fromorderinfo owhere isPaid = '已支付'

group byuserIdorder by total desc

查看总用户数和总金额

select count(userId),sum(total) from(select userId,sum(price) as total fromorderinfo owhere isPaid = '已支付'

group byuserIdorder by total desc) as t

select count(userId)*0.2,sum(total) from(select userId,sum(price) as total fromorderinfo owhere isPaid = '已支付'

group byuserIdorder by total desc)as t

limit限制前17000用户

select count(userId),sum(total) from(select userId,sum(price) as total fromorderinfo owhere isPaid = '已支付'

group byuserIdorder by total desclimit17129) t

统计销量 mysql_使用MySQL分析网络销售数据相关推荐

  1. mysql协议重传,MySQL · 源码分析 · 网络通信模块浅析

    MySQL 网络通信浅析 MySQL的网络通信协议主要包含以下几个层次,从最上层的MySQL数据包协议层到最底层的socket传输: | THD | Protocol | NET | VIO | SO ...

  2. 【java毕业设计】基于javaEE+原生Servlet+MySql的网络考试系统设计与实现(毕业论文+程序源码)——网络考试系统

    基于javaEE+原生Servlet+MySql的网络考试系统设计与实现(毕业论文+程序源码) 大家好,今天给大家介绍基于javaEE+原生Servlet+MySql的网络考试系统设计与实现,文章末尾 ...

  3. Mysql知识网络(持续更新)

    Mysql知识网络(持续更新) 前言 好记性不如烂笔头.最近学习了MYSQL的相关知识,方便以后复习以及知识点查询,记录一些知识点.本文通过基础知识+mysql优化+实战经验进行总结.也会分享一些自己 ...

  4. 使用NetFlow分析网络异常流量

    一.前言 近年来,随着互联网在全球的迅速发展和各种互联网应用的快速普及,互联网已成为人们日常工作生活中不可或缺的信息承载工具.然而,伴随着互联网的正常应用流量,网络上形形色色的异常流量也随之而来,影响 ...

  5. mysql 源码设计,java+mysql大学网络社区平台设计+源代码

    摘要如今,信息管理与信息系统的网络平台上,更多的都是一些静态信息的介绍,缺乏老师与老师之间, 老师与同学之间信息的交流的功能. 因此, 需要建立一个从 Web 1.0转换到 Web 2.0 的, 能够 ...

  6. TOOM舆情分析网络舆情监控平台研究现状

    随着网络舆情迅速发展,国内的舆情监测行业也日渐完善,舆情监控平台在企业发展过程中发挥重要作用,但同样也是有问题存在的,接下来TOOM舆情分析网络舆情监控平台研究现状? 一.网络舆情监控平台 网络舆情监 ...

  7. 截止2018年11月《最终幻想15》统计销量已经超过了840万份

    <最终幻想>系列游戏官网今日公布资料,<最终幻想15>的统计销量已经超过了840万份,成为了系列中销量第三高的作品.(仅次于<最终幻想7>与<最终幻想10&g ...

  8. Airbnb(爱彼迎)用户数据分析——tableau可视化和MySQL分析

    本文利用Airbnb用户的注册.订单和日志行为等数据,从用户画像.营销渠道转化率.订单漏斗分析三方面进行分析.我们需要考虑以下3个问题: 爱彼迎的目标用户是什么样的人群?有什么特点? 这些人群接受信息 ...

  9. Wireshark数据抓包分析(网络协议篇)1.2安装Wireshark

    Wireshark数据抓包分析(网络协议篇)1.2安装Wireshark Wireshark(前称Ethereal)是一个网络包分析工具.该工具主要是用来捕获网络包,并显示包的详细情况.本节将分别介绍 ...

最新文章

  1. pid调节软件_科学or艺术?——如何优化PID回路以实现最优性能
  2. 陶哲轩实分析命题10.1.7
  3. JVM-04垃圾收集Garbage Collection(上)【垃圾对象的判定】
  4. RDP8.0来了,Windows 7可以升级RDP了
  5. GCD之线程挂起与恢复
  6. oracle无会话锁表,深入浅出oracle锁 原理篇 停止无反应的sql会话
  7. C++读取和写入文件(fstream等)
  8. python:关于三级菜单的新手实现
  9. HTML5期末大作业:中华美德文化网站设计——中华美德文化(6页) HTML+CSS+JavaScript 中国传统美德文化网页HTML代码
  10. 金融行业实战项目:如何理解业务?
  11. matlab 整流滤波,基于Matlab_Simulink的整流滤波电路的建模与仿真
  12. iOS 高德地图(二)(进阶具体使用的细节)
  13. Laravel 6 结合网易/阿里邮箱基本邮件发送功能使用
  14. mt4服务器显示无连接,MT4登录显示“无效账户”,“无法连接”怎么解决
  15. pythonrender函数_Render函数
  16. 推荐8个免费好用的网站
  17. 目标跟踪系列三:ECO: Efficient Convolution Operators for Tracking(2016年11月)
  18. img的title和alt区别
  19. 红黑树详解,对插入旋转独到理解
  20. 区块链-以太坊学习资料汇总

热门文章

  1. android如何模糊图片处理图片,Android图片模糊效果
  2. /usr/bin/ld: warning: libpng16.so.16, needed by //home/syd/anaconda3/lib/libfreetype.so.6, not found
  3. abaqus和ansys做仿真哪个更好
  4. 从正则入门到处理姓名手机号脱敏
  5. [Python BeautifulSoup Threading] 多线程漫画爬虫
  6. Fluid 给数据弹性一双隐形的翅膀 -- 自定义弹性伸缩,mysql基础教程
  7. 内测分发是什么,都有哪些方式?
  8. java mkfifo_如何在Android中创建命名管道(mkfifo)?
  9. 通过手机号解析出手机号归属地的省、市、运营商、邮编、区号
  10. Linux常用命令:chmod修改文件权限 777和754