给mysql查询添加序号列
Posted 孟夏草木长
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了给mysql查询添加序号列相关的知识,希望对你有一定的参考价值。
select *,(@number := @number+1) AS number from (select u.mobile,u.`name`, ROUND((select sum(r.realAmount) from t_recharge r where r.userid=u.id and r.status=\'1\' ),2)rechargeSum, ROUND((select sum(w.realAmount) from t_withdrawal w where w.userid=u.id and w.status=\'1\' ),2)withdrawalSum, ROUND(sum(f.ownAmount),2)ownAmountSum, ROUND(sum(f.platformFunds),2)platformFundsSum, ROUND((select sum(fd.amount) from t_fund_detail fd where fd.userid=u.id and fd.type=\'3\' ),2)feeSum, ROUND(sum(f.result),2) cashResult , u.balance,u2.`name` as froms from t_user u left join t_financing f on f.userid=u.id LEFT JOIN t_user u2 ON u2.id = u.fromId group by u.id ) temp ,(select @number :=0) b
用到的是(@number := @number+1) AS number和(select @number :=0) b ,上面是多个表的例子
但个表的例子如下:
以上是关于给mysql查询添加序号列的主要内容,如果未能解决你的问题,请参考以下文章