小白问一条初级SQL

本资料无预览

如感兴趣请购买后下载

立即下载

资料简介:
table: id(primary key), card_num, process_time
不断有记录写进table,记录写入其写进数据库的时间为process_time
例如:  第一条     卡号码121212       20140808 08:08:08
              第二条     卡号码343434       20140808 08:09:08
              第三条     卡号码565656       20140808 08:10:08
              第四条     卡号码121212       20140808 08:11:08

求SQL: 输出所有 某同一card_num的每相邻两次记录的process_time大于一秒的记录

第一条与第四条为同一张卡,20140808 08:08:08 到 20140808 08:11:08  大于一秒 ---》 符合要求  最终输出 这两条
2014-11-27
浏览63068
下载0

已下载用户的评价

您还未下载该资料,不能发表评价;
查看我的 待评价资源
pshcatpshcat项目经理艾融软件2014-12-11
没用
with temp_table as ( select rownumber() over() as temp_id,id,card_num,process_time from tablename where card_num ='121212' order by id) select * from tablename where id in ( select a.id from temp_table a left join temp_table b on b.temp_id=a.temp_id+1 where b.process_time > a.process_time +1 second union select b.id from temp_table a left join temp_table b on b.temp_id=a.temp_id+1 where b.process_time > a.process_time +1 second)

贡献者

chendeshen软件开发工程师,华腾
X社区推广