sql - query between 2 rows -
have question. i'm doing select need grab 2 rows. have value of 13000.00000. need grab both rows 2 , 3 since falls between 10000 (min range) , 15000 (min range)
this statement pulls in row 2.
select * table1 13000 between table1.min_range , table1.max_range;
table1
row min_range max_range return_value 1 0.00000 9999.99900 1.15 2 10000.00000 14999.99900 1.25 3 15000.00000 19999.99900 1.35 4 20000.00000 24999.99900 1.14
you want first row falls below input , first row falls above input, both using min_range
descriminator:
select top 1 * table1 table1.min_range < @input order min_range desc union select top 1 * table1 table1.min_range >= @input order min_range;
this feels solution window function, maybe can post.
Comments
Post a Comment