我有这张 table
ID | Seq
------------
A 1
A 2
A 3
B 1
B 2
B 3
B 3 <--duplicate seq where ID=B
C 1
C 2
C 4 <--missing seq id number 3
D 1
D 2
. .
. .
有没有办法检测 Seq 列的逻辑是否/何时出现错误,特别是是否存在跳转和/或重复。
最佳答案
试试这个:
这应该在 sql server 和 Oracle 中都可以工作
select ID,seq
from(
select ID,seq,
row_number() over (partition by id order by seq ) rn
from t_seq)a
where a.seq<>a.rn
SQL fiddle demo for SQL server
SQL Fiddle demo for Oracle
关于sql - 如何使用 sql 检测错误的序列列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13250851/