实现功能:根据筛选条件实现排序功能
可以通过(@i:=@i+1)实现根据条件排序(注意:(SELECT @i:=0)必须放在末尾)
以下是图片中的sql语句:
SELECT (@i:=@i+1) AS ranking,recharge_list.user_id,recharge_list.rechargeAmout,recharge_list.count FROM
(
SELECT
t.user_id,t.user_phone,SUM(recharge_amout) AS rechargeAmout, COUNT(1) AS COUNT FROM recharge_list t
WHERE recharge_status=500 AND data_status=0 AND 1=1
GROUP BY t.user_id ,t.user_phone
ORDER BY rechargeamout DESC ) recharge_list,(SELECT @i:=0) AS t
sql实现rank排序(自增列)
最新推荐文章于 2024-07-29 09:03:14 发布