我在postgresql中搜索数字序列中断时遇到问题,我需要它,例如,如果我的seq列不按顺序,我将通过电子邮件通知,例如,我的序列is: 340,341,342
,如果它is: 340 342,343
,则这会导致序列失败。
您可以使用下一个查询来查找异常:
select count(*) from (
select id - (lag(id) over (order by id)) diff from tbl
) t where diff is not null and diff <> 1;
当查询结果不是0时,发现异常
SQL在线编辑器