How does java8 stream implement intra-group sorting?

the requirement is to query the latest 3 transactions of each customer. The sql is similar to the following:

select * 
  from (
    select , 
           rank() over(partition by  order by ) as ranking 
      from ) 
 where ranking > 3

how to use stream to sort within a group and take the first few items

Sep.22,2021
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-1b36e7b-41090.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-1b36e7b-41090.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?