给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  ,上面是多个表的例子

但个表的例子如下:

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

时间: 2024-09-28 19:35:05

给mysql查询添加序号列的相关文章

GridView添加序号列

在GridView控件第0列添加序号列: <asp:BoundField HeaderText="序号" > <ItemStyle HorizontalAlign="Center" /> <HeaderStyle HorizontalAlign="Center" Width="30px" /> </asp:BoundField> 为GridView添加OnRowDataBound

给DataTable添加序号列

如何在datatable中添加一序号列,编号从1依次递增,并且在第一列? /// <summary>        /// 在DataTable中添加一序号列,编号从1依次递增        /// </summary>        /// <param >DataTable</param>        /// <returns></returns>        private DataTable AddSeriNumToDat

AspxGridView添加序号列

using System.Globalization;//CultureInfo需要 protected void AspxGridView_stock_HtmlDataCellPrepared(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableDataCellEventArgs e) { if (e.DataColumn.Caption.Trim() == "序号") { e.Cell.Text = ((e.Vis

ASP.NET 为GridView添加序号列,且支持分页连续累计显示

为GridView添加序号列,且支持分页连续累计显示,废话不多说,直接上代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 T

mysql查询结果多列拼接查询

mysql查询结果多列拼接查询,主要场景是,列表中其中一列涉及另外一张表的多条数据,但是我只需要多条数据中的其中某一列(主子表场景) 关键字:GROUP_CONCAT sql语句如下: SELECT r.id,b.NAME AS group_name,GROUP_CONCAT( a.`name` ) province_name FROM config_rule AS r LEFT JOIN group AS g ON ( r.svg_id = g.id ) LEFT JOIN config_ru

mysql中给查询结果添加序号列

生成一个字段(非表中字段)用以记录排序   [类比为oracle数据库中的rownum] MySQL中一个表(表名:stuscore) 字段有:id(主键).stuid(学号).sname(学生姓名).subject(课程名称).score(分数) 列出数学成绩排名 (要求显示字段:排名,姓名 , 课程名称, 分数 , 学号) 用于排名的字段,查询时此处将其用 pm表示  select (@i:[email protected]+1)pm,s.* from stuscore s,(select

dataTable添加序号列

使用render( data, type, row, meta )的参数meta 直接新加一个列 columns: [ {data: "id", title: "id", visible: false, searchable: false}, {data: null, tile: "序号", visible: true, searchable: false}, {data: "name", title: "名称&qu

ASP.NET repeater添加序号列的方法

1.<itemtemplate> <tr><td> <%# Container.ItemIndex + 1%> </td></tr> </itemtemplate> 2.<itemtemplate> <tr><td> <%# this.rpResult.Items.Count + 1%> </td></tr> </itemtemplate>

RadGridView添加序号列

public class RowNumberColumn : GridViewDataColumn { public override System.Windows.FrameworkElement CreateCellElement(Telerik.Windows.Controls.GridView.GridViewCell cell, object dataItem) { TextBlock textBlock = cell.Content as TextBlock; if (textBlo