💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
### 下面是tp5 写法 ![](https://img.kancloud.cn/4a/2c/4a2cf7b48e19ae0012a6b0c2b51cc81e_1412x462.png) ~~~ SELECT t.* ,@rank:=@rank+1 AS pm FROM (SELECT sum(stay_time) as stay_time,t.goods_id,g.goods_name FROM `behavior_pages_logs_view_goods_time` `t` INNER JOIN `litestore_goods` `g` ON `g`.`goods_id`=`t`.`goods_id` WHERE `t`.`create_time` >= 1669824000 AND `t`.`goods_id` <> 0 GROUP BY `t`.`goods_id` ORDER BY `stay_time` DESC LIMIT 0,10) t , (SELECT @rank:=0) B ~~~ @rank:=0,0这个如果搞分页的话,每页需要动态设置,不然你到下一页,他拿返回的数据重新排位,所以需要告知下一页从第几名开始排,如果不分页可以不管 主要步骤: 1,@rank:=@rank+1 AS pm 和 (SELECT @rank:=0) B 其他的都是你之前的sql语句 2,个人理解原理是,你查出的结果,然后用rank变量,重新对你的结果,从上到下排序 参考: https://blog.csdn.net/bang152101/article/details/108583621