Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Group by multiple columns blues
Message
De
13/12/2012 15:45:31
 
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Divers
Thread ID:
01559592
Message ID:
01559617
Vues:
49
This message has been marked as the solution to the initial question of the thread.
Instead of concatenating Sight and Amount into a single field, create an anonymous type that has both of those values as properties and select each of the anonymous type's properties as part of the final select (not tested):
 Public Sub main()
        Dim o As New DataTable
        o.Columns.Add("Sight", GetType(String))
        o.Columns.Add("Account", GetType(String))
        o.Columns.Add("Amount", GetType(Double))
        o.Columns.Add("Amount1", GetType(Double))

        o.Rows.Add("S1", "A1",1,2)
        o.Rows.Add("S2", "A1",2,4)
        o.Rows.Add("S1", "A1",3,6)
        o.Rows.Add("S2", "A1",4,8)
        o.Rows.Add("S1", "A1",5,10)
        o.Rows.Add("S2", "A1",6,12)
        Dim q
        q = From record In o _
            Group By sightAndAccount = New With {Key .Sight = record("Sight"), Key .Account = record("Account")} 
            Into totAmount = Sum(record.Field(Of Double)("Amount")) _
            , totAmount1 = Sum(record.Field(Of Double)("Amount1"))
            Order By totAmount1
            Select sightAndAccount.Sight, sightAndAccount.Account, totAmount, totAmount1
        For Each o1 In q
            Debug.Print(o1.ToString)
        Next
end sub
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform