After php mysql grouping, take the first data and the last data in the group and do statistics. How to write MYSQL like this?

you need to count the sum of price and number by time grouping and take out the values of the first price and the last price in the group
. I haven"t been able to find the corresponding method for a long time. I hope you can guide me

.
Mar.29,2021

time grouping. The sorting field is not clear. Let's sort it by price

.
select 
    mtime,sum(price),sum(number),
    substring_index(group_concat(price order by price),',',1) min_price,
    substring_index(group_concat(price order by price),',',-1) max_price
from table group by mtime;

select min(price) as min_price, max(price) as max_price from (select mtime, code, sum(price) as price, sum(number) as number from table_xx group by mtime order by mtime desc) data
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf27e0-31dec.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf27e0-31dec.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?