Code to look for gaps in records in a table

WITH aquery AS
(SELECT emailid after_gap,
LAG(emailid,1,0) OVER (ORDER BY emailid) before_gap
FROM lgncc_emaildetails)
SELECT
before_gap, after_gap
FROM
aquery
WHERE
before_gap != 0
AND
after_gap – before_gap > 1
ORDER BY
before_gap;

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.