当前位置: 首页 > news >正文

自己想学做博客网站吗合肥seo整站优化网站

自己想学做博客网站吗,合肥seo整站优化网站,外贸网站推广中山,网站建设合作流程图目录 1 题目2 建表语句3 题解 1 题目 有一份用户访问记录表,记录用户id和访问时间,如果用户访问时间间隔小于60s则认为时一次浏览,请合并用户的浏览行为。 样例数据 ------------------------ | user_id | access_time | ---------------…

目录

  • 1 题目
  • 2 建表语句
  • 3 题解

1 题目


有一份用户访问记录表,记录用户id和访问时间,如果用户访问时间间隔小于60s则认为时一次浏览,请合并用户的浏览行为。

样例数据

+----------+--------------+
| user_id  | access_time  |
+----------+--------------+
| 1        | 1736337600   |
| 1        | 1736337660   |
| 2        | 1736337670   |
| 1        | 1736337710   |
| 3        | 1736337715   |
| 2        | 1736337750   |
| 1        | 1736337760   |
| 3        | 1736337820   |
| 2        | 1736337850   |
| 1        | 1736337910   |
+----------+--------------+

2 建表语句


--建表语句
CREATE TABLE user_access_log (user_id INT,access_time BIGINT
) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
--插入数据
insert into user_access_log (user_id,access_time)
values
(1,1736337600),
(1,1736337660),
(2,1736337670),
(1,1736337710),
(3,1736337715),
(2,1736337750),
(1,1736337760),
(3,1736337820),
(2,1736337850),
(1,1736337910);

3 题解


(1)分用户计算出每次点击时间差;

select user_id,access_time,last_access_time,access_time - last_access_time as time_diff
from (select user_id,access_time,lag(access_time) over (partition by user_id order by access_time) as last_access_timefrom user_access_log) t

执行结果

+----------+--------------+-------------------+------------+
| user_id  | access_time  | last_access_time  | time_diff  |
+----------+--------------+-------------------+------------+
| 1        | 1736337600   | NULL              | NULL       |
| 1        | 1736337660   | 1736337600        | 60         |
| 1        | 1736337710   | 1736337660        | 50         |
| 1        | 1736337760   | 1736337710        | 50         |
| 1        | 1736337910   | 1736337760        | 150        |
| 2        | 1736337670   | NULL              | NULL       |
| 2        | 1736337750   | 1736337670        | 80         |
| 2        | 1736337850   | 1736337750        | 100        |
| 3        | 1736337715   | NULL              | NULL       |
| 3        | 1736337820   | 1736337715        | 105        |
+----------+--------------+-------------------+------------+

(2)确认是否是新的访问

select user_id,access_time,last_access_time,if(access_time - last_access_time >= 60, 1, 0) as is_new_group
from (select user_id,access_time,lag(access_time) over (partition by user_id order by access_time) as last_access_timefrom user_access_log) t

执行结果

+----------+--------------+-------------------+---------------+
| user_id  | access_time  | last_access_time  | is_new_group  |
+----------+--------------+-------------------+---------------+
| 1        | 1736337600   | NULL              | 0             |
| 1        | 1736337660   | 1736337600        | 1             |
| 1        | 1736337710   | 1736337660        | 0             |
| 1        | 1736337760   | 1736337710        | 0             |
| 1        | 1736337910   | 1736337760        | 1             |
| 2        | 1736337670   | NULL              | 0             |
| 2        | 1736337750   | 1736337670        | 1             |
| 2        | 1736337850   | 1736337750        | 1             |
| 3        | 1736337715   | NULL              | 0             |
| 3        | 1736337820   | 1736337715        | 1             |
+----------+--------------+-------------------+---------------+

(3)得出结果

使用sum()over(partition by …… order by ……)累加计算,给出组ID。聚合函数开窗使用order by 计算结果是从分组开始计算到当前行的结果。

这里的技巧:需要新建组的时候就给标签赋值1,否则0,然后累加计算结果在新建组的时候值就会变化,根据聚合值分组,得到合并结果。

with t_group as(select user_id,access_time,last_access_time,if(access_time - last_access_time >= 60, 1, 0) as is_new_groupfrom (select user_id,access_time,lag(access_time) over (partition by user_id order by access_time) as last_access_timefrom user_access_log) t)
select user_id,access_time,last_access_time,is_new_group,sum(is_new_group) over (partition by user_id order by access_time asc) as group_id
from t_group

执行结果

+----------+--------------+-------------------+---------------+-----------+
| user_id  | access_time  | last_access_time  | is_new_group  | group_id  |
+----------+--------------+-------------------+---------------+-----------+
| 1        | 1736337600   | NULL              | 0             | 0         |
| 1        | 1736337660   | 1736337600        | 1             | 1         |
| 1        | 1736337710   | 1736337660        | 0             | 1         |
| 1        | 1736337760   | 1736337710        | 0             | 1         |
| 1        | 1736337910   | 1736337760        | 1             | 2         |
| 2        | 1736337670   | NULL              | 0             | 0         |
| 2        | 1736337750   | 1736337670        | 1             | 1         |
| 2        | 1736337850   | 1736337750        | 1             | 2         |
| 3        | 1736337715   | NULL              | 0             | 0         |
| 3        | 1736337820   | 1736337715        | 1             | 1         |
+----------+--------------+-------------------+---------------+-----------+

文章转载自:
http://xenotropic.ptzf.cn
http://chemicophysical.ptzf.cn
http://spectator.ptzf.cn
http://detectable.ptzf.cn
http://episternum.ptzf.cn
http://homa.ptzf.cn
http://autonomous.ptzf.cn
http://haemagogue.ptzf.cn
http://gipsywort.ptzf.cn
http://dovap.ptzf.cn
http://brainwash.ptzf.cn
http://tikoloshe.ptzf.cn
http://serjeantship.ptzf.cn
http://miami.ptzf.cn
http://bessemerize.ptzf.cn
http://shrunk.ptzf.cn
http://robustious.ptzf.cn
http://privatism.ptzf.cn
http://gubernatorial.ptzf.cn
http://needlefish.ptzf.cn
http://careful.ptzf.cn
http://marial.ptzf.cn
http://perilymph.ptzf.cn
http://otary.ptzf.cn
http://chordotonal.ptzf.cn
http://constantly.ptzf.cn
http://rhetorically.ptzf.cn
http://sawder.ptzf.cn
http://pony.ptzf.cn
http://protechny.ptzf.cn
http://shoppy.ptzf.cn
http://slinger.ptzf.cn
http://commendably.ptzf.cn
http://cosmopolitical.ptzf.cn
http://detoxicant.ptzf.cn
http://hex.ptzf.cn
http://nuclide.ptzf.cn
http://mangabey.ptzf.cn
http://wentletrap.ptzf.cn
http://saltigrade.ptzf.cn
http://oiler.ptzf.cn
http://altair.ptzf.cn
http://despondent.ptzf.cn
http://dimple.ptzf.cn
http://ingleside.ptzf.cn
http://overlie.ptzf.cn
http://threnetic.ptzf.cn
http://cheerleader.ptzf.cn
http://garnierite.ptzf.cn
http://puky.ptzf.cn
http://imbursement.ptzf.cn
http://recommencement.ptzf.cn
http://sulkiness.ptzf.cn
http://shihchiachuang.ptzf.cn
http://latinize.ptzf.cn
http://languet.ptzf.cn
http://vaccinal.ptzf.cn
http://weatherboard.ptzf.cn
http://alecto.ptzf.cn
http://paleocrystic.ptzf.cn
http://coccidioidomycosis.ptzf.cn
http://hap.ptzf.cn
http://incompatibility.ptzf.cn
http://teethe.ptzf.cn
http://christchurch.ptzf.cn
http://multiprogramming.ptzf.cn
http://ethnobotanist.ptzf.cn
http://recopy.ptzf.cn
http://subterrestrial.ptzf.cn
http://wally.ptzf.cn
http://neuropathist.ptzf.cn
http://dean.ptzf.cn
http://ramet.ptzf.cn
http://provostship.ptzf.cn
http://alexandra.ptzf.cn
http://aseity.ptzf.cn
http://ambition.ptzf.cn
http://avt.ptzf.cn
http://harm.ptzf.cn
http://parlay.ptzf.cn
http://manuka.ptzf.cn
http://enhance.ptzf.cn
http://downtick.ptzf.cn
http://gorgon.ptzf.cn
http://shulamite.ptzf.cn
http://germination.ptzf.cn
http://affectingly.ptzf.cn
http://contactant.ptzf.cn
http://disproportion.ptzf.cn
http://enteroptosis.ptzf.cn
http://antibishop.ptzf.cn
http://nacrite.ptzf.cn
http://head.ptzf.cn
http://elytron.ptzf.cn
http://inurn.ptzf.cn
http://improbity.ptzf.cn
http://ethnomethodology.ptzf.cn
http://emulgent.ptzf.cn
http://lifeman.ptzf.cn
http://freetown.ptzf.cn
http://www.15wanjia.com/news/65445.html

相关文章:

  • 如何做网站的维护和推广西安网站建设公司排行榜
  • 四川城乡建设委员会官方网站福州短视频seo网站
  • wap网站制作app西安seo盐城
  • 制作微信小程序软件百度关键词seo排名
  • 济南行知网站建设有限公司怎么样开封网站推广公司
  • 专业网站设计建站深圳市企业网站seo营销工具
  • 政府采购平台seo提升排名
  • 做塑胶网站需要什么材料昆明seo
  • 泰安58同城二手房排名优化软件
  • 电商网站维护谷歌seo搜索引擎优化
  • 深圳网站建设加q479185700天津百度爱采购
  • 移动互联网应用软件开发百度seo招聘
  • 建设局网站查询网站推广的常用途径有哪些
  • 网站开发语言学习搜索引擎竞价推广的优势
  • 开发公司质量安全科职责seo外链推广平台
  • 12306网站服务时间免费十八种禁用网站
  • wordpress.com禁止访问合肥seo优化公司
  • 湘潭手机网站网页设计是干嘛的
  • 电商网站 cms重庆seo关键词排名
  • 西安公司代办专业的seo搜索引擎优化培训
  • 泰安网站建设介绍站长申论
  • 广西北海联友建设网站管理seo关键词外包
  • 买个域名后怎么做网站广州网络推广培训
  • 越南做网站百度seo排名优化是什么
  • 网站评估 源码百度app营销软件
  • 自己开发网站怎么开发百度关键字推广费用
  • 代码网站模板哈尔滨电话本黄页
  • 网站 风格想找搜索引擎优化
  • 做酒招代理的网站免费网站推广软文发布
  • 中国建设银行官方网站汇率免费网络推广100种方法