码迷,mamicode.com
首页 > 数据库 > 详细

给mysql查询添加序号列

时间:2018-02-28 17:37:07      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:查询   info   hresult   例子   sel   ges   har   nan   charge   

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查询添加序号列

标签:查询   info   hresult   例子   sel   ges   har   nan   charge   

原文地址:https://www.cnblogs.com/-scl/p/8484479.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!