错了应该是
select * from (select * from table where data<7) t where
(select count(*) from t tx where abs(tx.id-t.id)=1)=2
or (select sum(tx2.id)%t.id from t tx2 where (tx2.id-t.id)<=2 and tx2.id>t.id)=3
or (select id-(sum(tx3.id)%t.id) from t tx3 where (tx3.id-t.id)>=-2 and tx3.id<t.id)=3
我终于看懂了:选出对应 连续3个(>3)data不超过7(按id排序) 的 date。
关键只在于data,与id无关。
楼主表意不清!
select * from (select * from table where data<6) t where
(select count(*) from t tx where abs(tx.id-t.id)=1)=2
or (select sum(id)%id from t tx2 where (tx2.id-t.id)<=2 and tx2.id>t.id)=3
or (select id-(sum(id)%id) from t tx3 where (tx3.id-t.id)>=-2 and tx3.id<t.id)=3
看能不能也让你晕一个