mysql中为排序添加排序名的方法
语法:
SELECT (@rownum:= @rownum+1) AS rank FROM (
SELECT * FROM (自己的表名)
) a,(SELECT @rownum:=0) b
使用方法:
SELECT a.userId,a.userName,a.sumInterval, a.tomatoNumber, @rownum := @rownum + 1 as rank
FROM (
SELECT
user_id AS userId,
user_name AS userName,
sum( tomato_time_interval ) AS sumInterval,
COUNT( user_id ) AS tomatoNumber
FROM
`tm_record_s`
WHERE
state = '1'
AND tomato_time_interval >= 1500
AND tomato_date = '2019-04⑵6'
GROUP BY
user_id
ORDER BY
COUNT( user_id ) DESC
) a, (SELECT @rownum :=0) b
本文来源:https://www.yuntue.com/post/58183.html | 云服务器网,转载请注明出处!