Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to find the missing number by sql
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00687629
Message ID:
00897064
Views:
21
You are not wrong. I needed this solution this evening, and thanks to UT search engine, I found your answer nearly 2 years after you posted this. :)

>AKhan,
>
>Although I did not fully tested it, I think this should work (I am usually wrong thou!)
>
>
>create cursor c_test (value I)
>insert into c_test values (2)
>insert into c_test values (3)
>insert into c_test values (4)
>insert into c_test values (6)
>insert into c_test values (7)
>insert into c_test values (12)
>insert into c_test values (13)
>insert into c_test values (14)
>insert into c_test values (16)
>insert into c_test values (17)
>select	value-1 as value ;
>	from	c_test ;
>	where 	value not in (select value+1 from c_test) and value-1 > 0 ;
>	into 	cursor c_result
>
>
>If you are only interested in the first missing number, then you can add:
>
>	order by value ;
>	top 1
>
>
>or for the last one:
>
>	order by value descending;
>	top 1
>
Mark McCasland
Midlothian, TX USA
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform