I have a table of identifiers and positions
CREATE TABLE
INSERT INTO
SELECT 36,1
UNION ALL SELECT 36,2
UNION ALL SELECT 36,3
UNION ALL SELECT 36,4
UNION ALL SELECT 36,5
UNION ALL SELECT 36,6
UNION ALL SELECT 44,1
UNION ALL SELECT 44,3
UNION ALL SELECT 44,4
UNION ALL SELECT 44,5
UNION ALL SELECT 44,6
What I'm trying to find is that there is any gap in the sequence of positions by identifier in this case, the gap between 44.1 and 44.3
I managed to parse together:
SELECT l.ID
,Start_Position = MIN(l.Position) + 1
,Stop_Position = MIN(fr.Position) - 1
FROM
LEFT JOIN
ON l.Position = r.Position - 1
LEFT JOIN
ON l.Position < fr.Position
WHERE r.Position IS NULL
AND fr.Position IS NOT NULL
GROUP BY l.ID
but it does not work if there are multiple ID values. It works if there is only one ID, 44.
thoughts, comments, suggestions?
thanks!
source
share