sql - query between 2 rows

前端 未结 3 684
臣服心动
臣服心动 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:10

    The following SQL query should work for you:

    DECLARE @TestRange NUMERIC(18,0)
    SET @TestRange = 13000
    SELECT *, (max_range - min_range) 
        FROM TABLE1 
        WHERE ((@TestRange >= min_range AND @TestRange <= max_range) 
           OR ((@TestRange >= min_range -  (max_range - min_range) 
           AND @TestRange <= max_range))) 
        ORDER BY min_range
    

    Tested with Microsoft SQL Server. Change the 13000 to whatever value you need to test against, or feel free to hard code the value

提交回复
热议问题