After oracle database grouping, take the maximum value of each group

The project team uses the oracle database, and now there are the following data, the table name is TEST :
Insert picture description here
Now I want to fetch the latest line of data after grouping by the group, that is, I want to fetch the data set marked as follows:
Insert picture description here
Solution:

SELECT a."ID",a."BUMENG_ID",a."GONGSI_ID",a."TIME"
  FROM (SELECT ROW_NUMBER() OVER(PARTITION BY GONGSI_ID ORDER BY TIME DESC) rn,
               TEST.*
          FROM TEST) a where a.rn=1

Results of the:
Insert picture description here

Guess you like

Origin blog.csdn.net/wujian_csdn_csdn/article/details/108005618