使用 Mysql 做断点记录查询

测试表结构

 

 

表中测试记录(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,很多不明白的地方请大家指正

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值