select * from (SELECT userId, receiverId, sum(totalDiamond) totalDiamonds FROM log_send_gifts where createTime between '2022-08-01' and '2022-10-25' and userId in (select userId from st_user_recharge where rechargeMoney >= 500000000) group by userId, receiverId order by userId, totalDiamonds desc) a where (select count(1) from (SELECT userId, receiverId, sum(totalDiamond) totalDiamonds FROM log_send_gifts where createTime between '2022-08-01' and '2022-10-25' and userId in (select userId from st_user_recharge where rechargeMoney >= 500000000) group by userId, receiverId order by userId, totalDiamonds desc) b where b.userId=a.userId and totalDiamonds>=a.totalDiamonds) <= 3
mysql group by 分组取前几例子参考
最新推荐文章于 2022-11-23 13:54:25 发布