如何仅在SQL中选择最小值的详细信息?

时间:2017-03-15 15:09:59

标签: sql oracle

我可以获得两个值的最小百分比,但我只需要名称和选择中的ID。

ID     NAME           CITY           ONE      TWO
--------------------------------------------------
2      Morales      Los Angeles      40        10
1      John           New York       60        20
4      Mary          San Diego       10        10

我需要获得最小值为1/2,并且只显示结果:

ID  NAME
---------
4   Mary

1 个答案:

答案 0 :(得分:0)

Select ID, NAME
from MYTABLE
where least(ONE,TWO) = (select min(least(ONE,TWO)) from MYTABLE);

如果你不想要莫拉莱斯,那么你可以这样做:

Select ID, NAME
from MYTABLE
where id = 
    (select id from 
        (select id from MYTABLE order by least(ONE,TWO), ONE*TWO)
    where rownum <= 1);