您现在的位置是: 首页> 学无止境> 心得笔记> 心得笔记

数据统计的sql语句基本详解

张伟江2021-09-11 14:59心得笔记1718人已围观

页面访问量:PV(Page View)访问量, 即页面浏览量(访问量)或点击量,衡量网站用户访问的网页数量;在一定统计周期内用户每打开或刷新一个页面就记录1次,多次打开或刷新同一页面则浏览量累计。

唯一页面访问量:在一定统计周期内同一个页面被同个访客多次访问只计算一次。

独立访客数:UV(Unique Visitor)独立访客,也叫唯一访客或去重访客,统计1天内访问某站点的用户数(以cookie为依据);访问网站的一台电脑客户端为一个访客。可以理解成访问某网站的电脑的数量。网站判断来访电脑的身份是通过来访电脑的cookies实现的。如果更换了IP后但不清除cookies,再访问相同网站,该网站的统计中UV数是不变的。如果用户不保存cookies访问、清除了cookies或者更换设备访问,计数会加1。00:00-24:00内相同的客户端多次访问只计为1个访客。统计一天内停留时间区间的独立访客数时,对于同一个访客来说只有这段时间内用户第一次进入的页面的停留时间才算独立访客,其余的都算重复访问。

独立IP数:IP(Internet Protocol)独立IP数,是指1天内多少个独立的IP浏览了页面,即统计不同的IP浏览用户数量。同一IP不管访问了几个页面,独立IP数均为1;不同的IP浏览页面,计数会加1。 IP是基于用户广域网IP地址来区分不同的访问者的,所以,多个用户(多个局域网IP)在同一个路由器(同一个广域网IP)内上网,可能被记录为一个独立IP访问者。如果用户不断更换IP,则有可能被多次统计。

新访客数:指的是统计周期内新增的独立访客。

回访客数:指的是统计周期内之前的所有独立访客数,独立访客数等于新访客数加回访客数。

平均停留时间:访客浏览单页面所花费的平均时长,页面的停留时长=进入下一个页面的时间-进入本页面的时间。

1、数据统计记录表

DROP TABLE IF EXISTS `fa_record`;
CREATE TABLE `fa_record` (
  `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `title` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '页面名',
  `url` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '页面地址',
  `device_id` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '设备ID',
  `type` tinyint(1) DEFAULT '1' COMMENT '来源:1=小程序,2=安卓,3=IOS',
  `ip` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT 'IP地址',
  `createtime` int(10) DEFAULT NULL COMMENT '创建时间',
  `play_time` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT '0' COMMENT '停留时间',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

2、求2021-09-06到2021-09-08之间每日安卓用户的页面访问量、唯一页面访问量、独立访客数、独立IP数、新访客数、回访客数、平均停留时间

页面访问量:

select count(*) cnt from fa_record where createtime between 1630857600 and 1631030400 and type=2
唯一页面访问量:
select count(*) cnt from (select count(*) from fa_record where createtime between 1630857600 and 1631030400 and type=2 group by url,device_id) as a
独立访客数:
select count(*) cnt from (select count(*) from fa_record where createtime between 1630857600 and 1631030400 and type=2 group by device_id) as a
独立IP数:
select count(*) cnt from (select count(*) from fa_record where createtime between 1630857600 and 1631030400 and type=2 group by ip) as a
新访客数:
select count(*) cnt from (select count(*) from fa_record where createtime between 1630857600 and 1631030400 and type=2 and device_id not in(select device_id from fa_record where createtime<1630857600) group by ip) as a

回访客数:
select count(*) cnt from (select count(*) from fa_record where createtime between 1630857600 and 1631030400 and type=2 and device_id in(select device_id from fa_record where createtime<1630857600) group by ip) as a
平均停留时间:
select avg(play_time) as cnt from fa_record where createtime between 1630857600 and 1631030400 and type=2

3、求2021-09-06到2021-09-08之间每日所有页面的安卓用户的页面访问量、唯一页面访问量、独立访客数、新访客数、回访客数、平均停留时间

页面访问量:


select title,count(*) cnt  from fa_record where createtime between 1630857600 and 1631030400 and type=2 group by title
独立访客数:
select title,count(*) cnt from (select title,count(*) cnt  from fa_record where createtime between 1630857600 and 1631030400 and type=2 group by title,device_id) a group by title
独立IP数:
select title,count(*) cnt from (select title,count(*) cnt  from fa_record where createtime between 1630857600 and 1631030400 and type=2 group by title,ip) a group by title
新访客数:
select title,count(*) cnt from (select title,count(*) cnt  from fa_record where createtime between 1630857600 and 1631030400 and type=2 and device_id not in (select device_id from fa_record where createtime<1630857600) group by title,device_id) a group by title
回访客数:
select title,count(*) cnt from (select title,count(*) cnt  from fa_record where createtime between 1630857600 and 1631030400 and type=2 and device_id in (select device_id from fa_record where createtime<1630857600) group by title,device_id) a group by title
平均停留时间:
select title,avg(play_time) cnt  from fa_record where createtime between 1630857600 and 1631030400 and type=2 group by title 
点赞(1) 打赏

文章评论 共有 0 条评论

暂无评论

本栏推荐

猜你喜欢

站点信息

  • 建站时间:2018年10月24日
  • 网站程序:fastadmin
  • 文章统计301篇文章
  • 标签管理标签云
  • 统计数据百度统计
  • 微信号:zwj982215226

打赏本站

  • 如果你觉得本站很棒,可以通过扫码支付打赏哦!
  • 微信扫码:你说多少就多少~
  • 支付宝扫码:你说多少就多少~

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部