mysql 查排名
SET @amount=0;
SET @rank=1;
SET @shunxu=0;
SELECT tmp2.id AS id,tmp2.name AS NAME,tmp2.amount AS amount,tmp2.rank AS rank
FROM (
SELECT tmp.id AS id,tmp.name AS NAME,tmp.amount AS amount,@shunxu:=@shunxu+1,IF(amount=@amount,@rank,@rank:=@shunxu) AS rank,@amount:=amount
FROM(
SELECT `ti`.`user_id` AS `id`,
(SELECT `tu`.`name` FROM `t_users` `tu` WHERE (`tu`.`id` = `ti`.`user_id`)) AS `name`,
SUM(`ti`.`amount`) AS `amount` FROM `t_invests` `ti`
GROUP BY `ti`.`user_id`
ORDER BY SUM(`ti`.`amount`)DESC) tmp)tmp2
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。