在asp gridview中添加新列包含单行类型的任意数量的重复行的计数详细信息?

时间:2014-03-21 07:56:10

标签: asp.net sql sql-server

我有

我在这个gridview中有一个asp网格,有很多重复的行,这些行有不同的余额细节,但id是相同的。

我想要什么

我想只显示一行具有相同ID且总余额明细,

将添加两列

  1. 第一列有行数
  2. 第二个添加了所有余额详细信息..
  3. 查询是:

        string qstr = "Select  id, WalletType, sno, TransferBy, TransferTo, Credit, debit, 
         Balance, vdate, Description, Descid from view_transactionsummary_dealer where vdate               between '" +  objdl.GetDBDate(Session["fromdate"].ToString().Replace("'", "''")) + "' and '" +
     objdl.GetDBDate(Session["todate"].ToString().Replace("'", "''")) + "'" and TransferBy = "Viewstate["TransferBy"]";
    

2 个答案:

答案 0 :(得分:0)

如果您希望仅针对具有总余额详细信息的相同ID显示单行 然后你必须使用group by idSUM(total balance)

答案 1 :(得分:0)

试试这个

string qstr = " SELECT id, WalletType, sno, TransferBy, TransferTo,Credit, debit, 
                SUM(Balance) Over(Partitiob by id order by (select NULL)), 
                Count(Balance) Over(Partitiob by id order by (select NULL)),vdate,                     
                Description, Descid 
                FROM view_transactionsummary_dealer 
                WHERE vdate Between
                '" +  objdl.GetDBDate(Session["fromdate"].ToString().Replace("'", "''")) 
                + "' AND '" +
                objdl.GetDBDate(Session["todate"].ToString().Replace("'", "''")) 
                + "'" AND 
                TransferBy = "Viewstate["TransferBy"] Group By id,WalletType,sno,TransferBy,TransferTo,Credit, debit,vdate,Description, Descid ";