none
Two Column, one with SUM??? RRS feed

  • Question

  • Hi All,

     

    I’m writing a app in VB and making LINQ queries against a SQL Express DB. I know the general syntax of LINQ and already have several queries that work.

     

    My issue that I have now is on a SUM query with 2 columns and SUM on only 1 column.

    In SQL the below syntax works but I have no idea how to convert it to LINQ. Any help would be greatly appreciated.

     

    SELECT     Tail, SUM(TailCount) AS df

    FROM         TailCount

    GROUP BY Tail

    ORDER BY Tail

    Wednesday, November 17, 2010 2:49 PM

Answers

  • Great.
    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solucion de esta pregunta te ha sido útil.
    • Marked as answer by BMWBear Wednesday, November 17, 2010 8:34 PM
    Wednesday, November 17, 2010 7:17 PM

All replies

  • Hi,

    Look at at this sample:

    http://msdn.microsoft.com/en-us/vbasic/bb737926.aspx#grpbysum

    Best regards,

    JAReyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solucion de esta pregunta te ha sido útil.
    Wednesday, November 17, 2010 6:38 PM
  • Hi JA,

    I have been able to get the following to work...

     

    Dim ACFTTial4 = (From tailcounts In db.TailCounts _

     

    Where tailcounts.Model = "55" _

     

    Group tailcounts By tailcounts.Tail Into g = Group _

     

    Order By Tail Select New With _

    {.dr = (Tail +

    " " + CStr(g.Sum(Function(p) p.TailCount)))})

    Wednesday, November 17, 2010 6:49 PM
  • Great.
    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solucion de esta pregunta te ha sido útil.
    • Marked as answer by BMWBear Wednesday, November 17, 2010 8:34 PM
    Wednesday, November 17, 2010 7:17 PM