测试表结构
表中测试记录(flowid为各个分店的流水号,系统异常时,在这张汇总表中会发生断点的现象)
查询sql
select name as 分店, flowid as 分店流水号, date as 日期 from store s1 where not exists(
select * from store s2 where s1.flowid = s2.flowid-1 and s1.name = s2.name
union all
select * from store s3 where s1.id = s3.id and s3.flowid in (select max(flowid) flowid from store s3 group by name)
union all
select * from store s4 where s1.id = s4.id and (s4.date > '2009-08-26 00:00:00' or s4.date < '2009-08-24 00:00:00')
)
结果显示
初学sql,很多不明白的地方请大家指正