Re: Query to find a missing number



Mahesh BS wrote:

Hello,
I need to write a query to find out a set of missing number in a given
sequence.
Eg : a Column in some table has the following data
Col1
1
2
3
4
5
6
8
9
10
Here I need to write a query to find out that number 7 is missing in the
given sequence.
One possible solution is by using any loop. But I am looking out if the same
can be achieved using any query.
Thanks in advance.
Regards,
Mahesh



after some tests, i am arrived to this:

select (a.col1 + 1)
from tab1 a
where not exists
(select 1
from tab1 b
where b.col1 = (a.col1 + 1))
and a.col1 not in
(select max(c.col1)
from tab1 c)
order by 1

try it!
fabio



--
.... per questo oggi si dice:"Davanti alla Rossa c'è solo la pista..."
f.

Correr, competir, eu levo isso no sangue, é parte de minha vida
Ayrton Senna da Silva

leva UNA MARCIA per rispondermi in privato .



Relevant Pages

  • Re: Query to find amissing number
    ... Here I need to write a query to find out that number 7 is missing in the ... given sequence. ... giving you a quick way to determine if any gaps exist. ...
    (comp.databases.sybase)
  • RE: Find missing Working Days
    ... contains one field (intNumbers) and the values of 0 through 9. ... I then create a query that generates numbers from zero through ... Can anyone think of a query that can check if any days are missing? ... results into a table if a number from 1 to 5 is out of sequence but I wonder ...
    (microsoft.public.access.queries)
  • Re: find missing numbers
    ... This will report the first missing number of each sequence. ... similar subquery to find the high end of each missing sequence. ... For a complete query in my response, provide your table name and column ...
    (microsoft.public.access.queries)
  • Re: finds gaps in sequential numbers?
    ... I too am looking for a way to determine missing numbers in a sequence. ... "Tom Ellison" wrote: ... This allows the query to look at the ...
    (microsoft.public.access.queries)
  • Re: Spin calling John 100% identity (Human & Gekko)
    ... Unfortunately there are no other sequences to use in checking the accuracy of that EST, i.e. no Gekko atpase sequences, and the study the sequence comes from is unpublished. ... Query 4427 ... Sbjct 6 ... TCTGACATGGGGCCACCCCACAGGTCAGAGTGGTGGTAGAACCCCTTCAGGACTCCCAGC 245 ...
    (talk.origins)