利用Hive实现求两条相邻数据时间差

1.Hive row_number() 函数的高级用法 row_num 按照某个字段分区显示第几条数据

select imei,ts,fuel_instant,gps_longitude,gps_latitude,row_number() over (PARTITION BY imei ORDER BY ts ASC) as row_num from sample_data_2

2.row_num 是相互连续的,join 自身,然后时间相减可求差
create table obd_20140101 as

  select a.imei,a.row_num,a.ts,COALESCE(unix_timestamp(a.ts, ‘yyyy-MM-dd HH:mm:ss.S‘), 0) - unix_timestamp(b.ts, ‘yyyy-MM-dd HH:mm:ss.S‘) as intervel ,a.fuel_instant,a.gps_speed as obd_speed,a.gps_status,a.gps_longitude,a.gps_latitude,a.direct_angle,a.obdspeed from obddata_20140101 a join obddata_20140101 b on a.imei = b.imei and a.row_num = b.row_num +1

时间: 2024-08-07 10:00:43

利用Hive实现求两条相邻数据时间差的相关文章

SQLServer 分组查询相邻两条记录的时间差

原文:SQLServer 分组查询相邻两条记录的时间差 首先,我们通过数据库中表的两条记录来引出问题,如下图 以上为一个记录操作记录的表数据.OrderID为自增长列,后面依次为操作类型,操作时间,操作人. 现在的问题是:要求筛选出数据库中从“接收”到“送出”的时间差超过2天的全部记录.即如上图两笔单据中,红色框既是要筛选出的,绿色框为正常过滤的. 为了定位相邻记录,方法为给查询语句的返回记录加个自动编号列放入临时表中,再对临时表进行操作. --1.首先查出表中符合條件的所有信息 select

求两条对角线上行、列下标均为偶数的各元素之和。

//求两条对角线上行.列下标均为偶数的各元素之和. #include <stdio.h> int main() { int sum=0; int i,j; int a[5][5]; //为数组赋值 for(i=0;i<5;i++) { for(j=0;j<5;j++) { scanf("%d",&a[i][j]); } } //求两条对角线上行.列下标均为偶数的各元素之和. for(i=0;i<5;i++) { for(j=0;j<5;j++

hive实现根据用户分组,按用户记录求上下两条记录的时间差

在mysql,数据如下:#查询某一用户该日抽奖时间 select draw_time from user_draw_log where user_id = 1 and draw_date='2016-03-09' order by id; +---------------------+ | draw_time | +---------------------+ | 2016-03-09 13:52:46 | | 2016-03-09 13:52:53 | | 2016-03-09 13:53:0

求两条直线(线段)的交点

转自: http://blog.csdn.net/dgq8211/article/details/7952825 如图,如何求得直线 AB 与直线 CD 的交点P? 以上内容摘自<算法艺术与信息学竞赛>. 思路就是利用叉积求得点P分线段DC的比,然后利用高中学习的定比分点坐标公式求得分点P的坐标. 看不懂的可以去复习下 定比分点 的知识. 1 #include <math.h> 2 #include <stdio.h> 3 #include <string.h&g

Intersecting Lines--POJ1269(判断两条直线的关系 &amp;&amp; 求两条直线的交点)

http://poj.org/problem?id=1269 我今天才知道原来标准的浮点输出用%.2f   并不是%.2lf  所以wa了好几次 题目大意:   就给你两个线段 然后求这两个线段所在的直线的关系  有共线  平行  和相交 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<ctype.h> #include<math.h> #define N 200

求两条直线的交点

CvPoint GetTwoLineCrossPoint(const int& x1, const int& y1, const int& x2, const int& y2, const int& x3, const int& y3, const int& x4, const int& y4) { //第一条直线的参数 double a0 = y1 - y2; double b0 = x2 - x1; double c0 = x1 * y2

AS3 求两条直线的交点

//粘贴到帧上运行即可 var p1Start:Point = new Point(0,0); var p1End:Point = new Point(50,50); var p2Start:Point = new Point(50,50); var p2End:Point = new Point(100,100); var p:Point = new Point(); trace(checkPoint()) function checkPoint() { if (p1Start.x == p1

MYSQL 当有两条重复数据时 保留一条

delete from test  where id in (select id from (select  max(id) as id,count(text) as count from test group by text having count >1 order by count desc) as tab ) 测试代码 INSERT IGNORE INTO test_1(text,text2) values ('1111','22222'); INSERT IGNORE INTO tes

c编程:求出4&amp;#215;4矩阵中最大和最小元素值及其所在行下标和列下标,求出两条主对角线元素之和。

//求出4×4矩阵中最大和最小元素值及其所在行下标和列下标,求出两条主对角线元素之和 #include <stdio.h> int main() { int sum=0; int max,min; int max1,max2;//记录最大值的坐标 int min1,min2;//记录最小值的坐标 int i,j; int a[4][4]; //为数组赋值 for(i=0;i<4;i++) { for(j=0;j<4;j++) { scanf("%d",&