user10054130
user10054130

Reputation:

SQL Group by column

I have a SQL dbo.bugetyear & Output below.

 NameofAccount    BudgetMonth    Balance      AccountCategory      Year
  sales              1            -344.78        income              2018
  sales              2            -2744.78       income              2018
  sales              3            -8745.78       income              2018
  INTEREST INC       1             7866          Interest income     2018
  INTEREST INC       2             1766          Interest income     2018

I want to sum by Account Category.

  NameofAccount      Balance      AccountCategory      Year       
     sales           -3089.56       income              2018
   INTEREST INC       9632           Interest income    2018

Upvotes: 0

Views: 44

Answers (1)

jigga
jigga

Reputation: 614

Is there an error in the sales sum? If so, here is a solution:

SELECT
        NameOfAccount,
        SUM(Balance) AS Balance,
        AccountCategory,
        Year
FROM dbo.bugetyear
GROUP BY NameOfAccount, AccountCategory, Year 

Upvotes: 2

Related Questions