Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2013

    Unanswered: Simple subquery summary

    I created a query and want to do if it is possible a subquery with summary, below is my code. Is it possible. I have never done a subquery before.

    SELECT [GL Description], SUM(Amount) AS [Prior YTD Amount], Year, Month
    FROM dbo.vlv_PriorYrDetailExpenses
    GROUP BY [GL Description], Year, Month
    HAVING (Year = @Year) AND (Month <= @Month)

    I get this result using the above query

    GL_Description Amount Year Month

    Auto Expense 100.00 2015 1
    Auto Expense 100.00 2015 2
    Off. Expense 200.00 2015 1
    Off.Expense 200.00 2015 2
    Contract Labor 1000.00 2015 1
    Contract Labor 1000.00 2015 2
    Cleaning Labor 2000.00 2015 1
    Cleaning Labor 2000.00 2015 2

    I would like to get this result instead without the month.

    GL_Description Amount Year

    Auto Expense 200.00 2015
    Off. Expense 400.00 2015
    Contract Labor 2000.00 2015
    Cleaning Labor 4000.00 2015

    Any help will be appreciated. Thank you in advance.

  2. #2
    Join Date
    Feb 2004
    In front of the computer
    Provided Answers: 54
    Just remove the month from the column list and the group by clause.

    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Mar 2013
    Quote Originally Posted by Pat Phelan View Post
    Just remove the month from the column list and the group by clause.

    So, simple! Thanks I really appreciate your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts