![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Let's say I have a result set (records) containing numbers such as: 0 1 2 3 9 16 21 45 100 101 102 103 104 105 106 How might someone write a procedure to get the next lowest number in this sequence? In this case it would be: 4. Some combination of Select, Min & When, I am sure, but it escapes me at the moment. Thoughts? Thanks... |
#3
| |||
| |||
|
|
"Zamdrist" <zamdr... (AT) gmail (DOT) com> wrote in message news:1191525448.343516.292440 (AT) k79g2000hse (DOT) googlegroups.com... Let's say I have a result set (records) containing numbers such as: 0 1 2 3 9 16 21 45 100 101 102 103 104 105 106 How might someone write a procedure to get the next lowest number in this sequence? In this case it would be: 4. Some combination of Select, Min & When, I am sure, but it escapes me at the moment. Thoughts? Thanks... SELECT MIN(x)+1 x FROM tbl t WHERE NOT EXISTS (SELECT x FROM tbl WHERE x = t.x+1); -- David Portas |
#4
| |||
| |||
|
|
Let's say I have a result set (records) containing numbers such as: 0 1 2 3 9 16 21 45 100 101 102 103 104 105 106 How might someone write a procedure to get the next lowest number in this sequence? In this case it would be: 4. Some combination of Select, Min & When, I am sure, but it escapes me at the moment. Thoughts? Thanks... |
#5
| |||
| |||
|
|
Let's say I have a result set (records) containing numbers such as: 0 1 2 3 9 16 21 45 100 101 102 103 104 105 106 How might someone write a procedure to get the next lowest number in this sequence? In this case it would be: 4. Some combination of Select, Min & When, I am sure, but it escapes me at the moment. |
#6
| |||
| |||
|
|
How might someone write a procedure to get the next lowest number in this sequence? In this case it would be: 4. |
#7
| |||
| |||
|
|
On Oct 4, 2:17 pm, Zamdrist <zamdr... (AT) gmail (DOT) com> wrote: In this case it would be: 4. SELECT MIN(t2.x +1) FROM t FULL JOIN t t2 ON t.x = t2.x +1 WHERE t.x IS NULL; |
#8
| |||
| |||
|
|
Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. If you know how, follow ISO-11179 data element naming conventions and formatting rules. How might someone write a procedure to get the next lowest number in this sequence? In this case it would be: 4. No; read your own specs! The answer is -1. Or maybe -0.0000...1 if the column is a DECIMAL or a FLOAT. If you had posted DDL that limited the column to non-negative integers, then Dave's answer would work. |
#9
| |||
| |||
|
|
CELKO...explain to me then why everyone else in the thread knew *exactly* what was asked for? Are you predisposed to being a dickhead, or is it just me? |

#10
| |||
| |||
|
|
CELKO...explain to me then why everyone else in the thread knew *exactly* what was asked for? Are you predisposed to being a dickhead, or is it just me? |
It's you ![]() One of the hardest things for newbies to learn is how to write a clear spec. Anohter one is not to use profanity in newsgroups .. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |