Finding the lowest value in a table greater than a certain value

前端 未结 6 941
臣服心动
臣服心动 2021-02-09 14:01

Say I have the following data

Name      Value
===============
Small        10
Medium      100
Large      1000

Imagine that these represent the

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-09 14:37

    This works. Replace the "5" with your parameter.

    select min(basket_value) as basket_value
    from baskets
    where basket_value > 5 
       or basket_value = (select max(basket_value) from baskets)
    

    Simple script to generate test data:

    create table baskets(
      basket_name varchar2(20)
     ,basket_value number
    );
    
    insert into baskets(basket_name,basket_value) values('Small',10);
    insert into baskets(basket_name,basket_value) values('Medium',100);
    insert into baskets(basket_name,basket_value) values('Large',1000);
    commit;
    
    --drop table baskets;  --run when finished
    

提交回复
热议问题