mysql中如何添加排序名

1240
2020/12/19 17:33:40
栏目: 云计算
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

mysql中如何添加排序名

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-26'

GROUP BY

user_id

ORDER BY

COUNT( user_id ) DESC

) a, (SELECT @rownum :=0) b

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: mysql分页查询语句怎么写