SQL - How to select a row having a column with max value

前端 未结 9 812
悲&欢浪女
悲&欢浪女 2020-11-29 02:38
date                 value

18/5/2010, 1 pm        40
18/5/2010, 2 pm        20
18/5/2010, 3 pm        60
18/5/2010, 4 pm        30
18/5/2010, 5 pm        60
18/5/20         


        
9条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 02:49

    Technically, this is the same answer as @Sujee. It also depends on your version of Oracle as to whether it works. (I think this syntax was introduced in Oracle 12??)

    SELECT *
    FROM   table
    ORDER BY value DESC, date_column ASC
    FETCH  first 1 rows only;
    

    As I say, if you look under the bonnet, I think this code is unpacked internally by the Oracle Optimizer to read like @Sujee's. However, I'm a sucker for pretty coding, and nesting select statements without a good reason does not qualify as beautiful!! :-P

提交回复
热议问题