The project team uses the oracle database, and now there are the following data, the table name is TEST :
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:
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: