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

前端 未结 9 811
悲&欢浪女
悲&欢浪女 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:44

    Answer is to add a having clause:

    SELECT [columns]
    FROM table t1
    WHERE value= (select max(value) from table)
    AND date = (select MIN(date) from table t2 where t1.value = t2.value)
    

    this should work and gets rid of the neccesity of having an extra sub select in the date clause.

提交回复
热议问题