tugrul
tugrul

Reputation: 156

How to identify sequenced record gaps by field on MySQL

I can find sequenced record gaps where sequenced weeks with same numbers using following query.

SELECT * FROM pointed_numbers A WHERE EXISTS (
    SELECT * FROM pointed_numbers B WHERE A.number = B.number AND (A.week = B.week + 1 XOR A.week = B.week - 1)
) ORDER BY A.number, A.week;

How can I identify each gaps without stored procedure. I have tried with user-defined variable but I had no success.

Upvotes: 0

Views: 113

Answers (1)

DWright
DWright

Reputation: 9500

Take a look at http://www.artfulsoftware.com/infotree/queries.php and look at the stuff under the "sequences" section. This is a super super helpful site with recipes for how to do complicated things in mysql!

Upvotes: 1

Related Questions