
1 RemRain 2014 年 12 月 1 日 SELECT * FROM xxx 然后在程序里面搞定 |
2 zts1993 2014 年 12 月 1 日 |
3 phoneli 2014 年 12 月 1 日 感觉这样的逻辑业务。不应该在用sql占用数据库。你就select * 出来,然后用shell处理一下。 |
4 jianghu52 2014 年 12 月 1 日 我好奇的是相邻两条这个要求怎么在sql里面体现出来 |
5 Automan 2014 年 12 月 1 日 其实你只要DISTINCT就可以了。。因为只要是不同的时间,那肯定是大于一秒 |
6 msg7086 2014 年 12 月 1 日 数据库里哪来相邻…… |
7 7654 2014 年 12 月 1 日 这样解决吧,数据库应该只提供数据,不做分析 |
8 beginor 2014 年 12 月 1 日 对 MySql 不熟悉, 不过感觉用游标应该可以解决的; 如果是 SQL Server 的话, 除了游标之外, 可以使用 LEAD/LAG 函数来解决 http://msdn.microsoft.com/zh-cn/library/hh231256.aspx |
9 loading 2014 年 12 月 1 日 via Android 全选出来,order by id,process_time 然后在程序里判断就好了。 |
10 hcymk2 2014 年 12 月 1 日 select a.id ,b.id ,a.card_num from (select id ,process_time,card_num, @num1 := @num1 + 1 as row_number from (SELECT @num1:=1) r1, you_table_name order by card_num,process_time ) a , (select id ,process_time,card_num, @num2 := @num2 + 1 as row_number from (SELECT @num2:=0) r2, you_table_name order by card_num,process_time) b where a.row_number=b.row_number and a.card_num=b.card_num and b.process_time-a.process_time>1; 献丑了。 |
11 ixiaohei 2014 年 12 月 1 日 |
13 jucelin 2014 年 12 月 1 日 via Android 可以考虑提前预处理数据,例如插入前就计算出与上一次的时间差算放进库里去。 |
14 lu18887 2014 年 12 月 2 日 via iPhone 楼上说程序处理的各位仁兄,当数据量足够大,计算要求足够复杂的时候数据库的SQL还是不错的选择,前提是要能写对。 |
15 jinghli 2014 年 12 月 2 日 这是典型的SQL window function.不算是太小白的问题。我简单写了个postgresql可用的。 SELECT card_num FROM ( SELECT lag(process_time) OVER (PARTITION BY card_num ORDER BY process_time) AS prev_process_time, card_num, process_time FROM your_table ) x WHERE prev_process_time is NULL --not sure whether you need this OR (process_time - prev_process_time > '1 second'::interval) |