sql - query between 2 rows

前端 未结 3 678
臣服心动
臣服心动 2021-01-24 15:38

Have question. I\'m doing a select where I need to grab 2 rows. I have a value of 13000.00000. I need to grab both rows 2 and 3 since it falls between the 10000 (min range) an

3条回答
  •  醉话见心
    2021-01-24 16:13

    You want to get the first row that falls below the input and the first row that falls above the input, both using MIN_RANGE as the descriminator:

    select top 1 *
    from TABLE1
    where TABLE1.MIN_RANGE < @input
    order by MIN_RANGE desc
    UNION
    select top 1 *
    from TABLE1
    where TABLE1.MIN_RANGE >= @input
    order by MIN_RANGE;
    

    This feels like a solution for a window function, which maybe someone can post.

提交回复
热议问题