Group by group query the latest records

I have also seen some posts on the Internet, but there are still some problems in the actual operation. Please take a look at what the problem is.
demand is the latest record (add_time) of each item (goods_id) in the query tp_inventory_ log table;
the first statement I tried:

 select * from (select goods_id, price, add_time from tp_inventory_log order by add_time desc limit 50) as til group by goods_id order by add_time desc limit 25;

shows that the result is

:



the only difference between these two statements is that there are more subquery statements in the first statement than limit 50, but the results are quite different.
1. The result of the second query statement does not show the data from April 23rd; the record with
2.goods_id of 1081 does not show the same result in the two query statements, and the desired result is the 17:14 result obtained by the first query statement.

Mar.07,2021

I'll give you an example of mine, and you can deal with it yourself:

select group_concat(id) id_list,name from ttt group by name; id
select group_concat(id order by id SEPARATOR '_') from ttt group by name; id"_"
select substring_index(group_concat(id order by id SEPARATOR '_'),'_',2) from ttt group by name; id,"_"
:group_concatint

SELECT goods_id, price, add_time FROM tp_inventory_log WHERE primary key ID IN (SELECT max (primary key ID) FROM tp_inventory_log GROUP BY goods_id) DESC LIMIT 25;
the larger the primary key and the larger the time, you can consider this idea


refer to the following code:
get the latest after-sales record in all order items:
self-connection does not require group by

SELECT 
  `order_refund`.*
FROM
  `order_refund` 
 LEFT JOIN `order_refund` ort 
    ON `ort`.`order_item_id` = `order_refund`.`order_item_id` 
    AND `order_refund`.`id`  < `ort`.`id` 
WHERE `ort`.`id` IS NULL 
Menu