How to find the record in a table that contains the maximum value?

前端 未结 4 1536
没有蜡笔的小新
没有蜡笔的小新 2020-12-09 06:01

Although this question looks simple, it is kind of tricky.

I have a table with the following columns:

table A:
  int ID
  float value
  datetime date         


        
4条回答
  •  轮回少年
    2020-12-09 06:24

    This is just what analytic functions were made for:

    select group,
           id,
           value
    from   (
           select group,
                  id,
                  value,
                  date,
                  max(date) over (partition by group) max_date_by_group
           from A
           )
    where  date = max_date_by_group
    

提交回复
热议问题