我有这样的表格,我想选择这些行:
所以如果连续速度= 0的记录超过3条,则选择它。
答案 0 :(得分:1)
SELECT *
FROM table_name tn
WHERE
((SELECT COUNT(1) FROM table_name WHERE id=tn.id+1 AND speed=0)>0 AND
(SELECT COUNT(1) FROM table_name WHERE id=tn.id+2 AND speed=0)>0) OR
((SELECT COUNT(1) FROM table_name WHERE id=tn.id-1 AND speed=0)>0 AND
(SELECT COUNT(1) FROM table_name WHERE id=tn.id-2 AND speed=0)>0) OR
((SELECT COUNT(1) FROM table_name WHERE id=tn.id+1 AND speed=0)>0 AND
(SELECT COUNT(1) FROM table_name WHERE id=tn.id-1 AND speed=0)>0)
答案 1 :(得分:0)
select *
from table_name
where speed=0
and (select count(*) from table_name where speed=0) > 3