給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  ,上面是多個表的例子spa

但個表的例子以下:code

相關文章
相關標籤/搜索