Re: Query to find a missing number
- From: Ferrarista XXL <ferraristaxxlUNAMARCIA@xxxxxxxxx>
- Date: Thu, 13 Jul 2006 19:50:40 +0200
Mahesh BS wrote:
Hello,after some tests, i am arrived to this:
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
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 .
- References:
- Query to find a missing number
- From: Mahesh BS
- Query to find a missing number
- Prev by Date: Re: De-normalizing query
- Next by Date: Check if a Table is used in any sp or function
- Previous by thread: Query to find a missing number
- Next by thread: Re: Query to find a missing number
- Index(es):
Relevant Pages
|