mysql查询相邻数据时间差
来源:互联网 发布:对网络课程的认识 编辑:程序博客网 时间:2024/06/10 06:15
select A.user_id,A.punch_time,TIMESTAMPDIFF(SECOND,A.punch_time,B.punch_time) sub_seconds
from(
select a.*,(@i := @i + 1) as ord_num from t_punch_cade a,(select @i := 1) d order by user_id,punch_time
) as A LEFT JOIN (
select a.*,(@j := @j + 1) as ord_num from t_punch_cade a,(select @j := 0) c order by user_id,punch_time
from(
select a.*,(@i := @i + 1) as ord_num from t_punch_cade a,(select @i := 1) d order by user_id,punch_time
) as A LEFT JOIN (
select a.*,(@j := @j + 1) as ord_num from t_punch_cade a,(select @j := 0) c order by user_id,punch_time
)as B on A.ord_num=B.ord_num and A.user_id=B.user_id
比如排序之后我们想计算两条相邻记录的时间差,因为mysql没有窗口函数所以要么模拟窗口函数要么使用表自关联
我们可以使用增加一个错位序号的字段,然后使用序号条件关联
原文地址:http://blog.csdn.net/tangpengh/article/details/53171313
阅读全文
0 0
- mysql查询相邻数据时间差
- mysql 计算相邻两条记录的时间差
- mysql数据中计算时间差函数
- sql 查询 某列数据 相邻行的间隔值
- mysql 时间差
- mysql时间差
- mysql 时间差
- mysql 实现相邻两条数据相减
- MySQL 时间差、每15分钟统计一次数据
- SqlServer 相邻数据(时间上相邻) 相邻状态 数据合并
- 删除相邻重复数据
- 数据库中相邻两行的交易时间差
- Mysql查询重复数据
- php查询MySQL数据
- MySQL 查询数据不一致
- mysql随机查询数据
- mysql 随机查询数据
- MYSQL 常用数据查询
- 【汇编】near指针,far指针,huge指针
- Ubuntu14.04安装Tomcat7.0 配置环境变量(亲自搭建 图解)
- 加强对公证服务知识产权保护工作的组织领导
- 获取短信接口开发的appkey和SDKAPPID-短信平台验证码开发5
- 大学开设大数据专业,都安排了哪些课程?
- mysql查询相邻数据时间差
- viewer.js插件简单使用说明
- 安卓学习笔记(实战)
- android studio 快速集成腾讯bugly
- 评测指标—准确率(Precision)、召回率(Recall)、F值(F-Measure)
- Go学习笔记(二)
- [EMNLP2017]End-to-End Neural Relation Extraction with Global Optimization
- Unity3: DoTween插件的简单使用
- leetcode 42|407. Trapping Rain Water 1|2