Add Column in SQL server

Asked

Viewed 18,490 times

3

I’m working on a system that I need to realize a sum that will be made into a view SQL Server. In C# I know how to resolve this. I would like to resolve using SQL.

ColA    ColB
200911  1634,50
200911  558,29
200911  2446,66
200911  2860,90
200911  37905,01
200911  1238,11
200912  1634,50
200912  129191,82
200912  107644,42
200912  212634,97
200912  214817,55
200912  18754,56
200912  63911,39
200912  61991,81
201001  148,53
201001  17946,07
201001  1181,59
201001  108018,78
201001  3287,28
201001  191,17
201001  305,94

The result I need to arrive at is this :

ColA    ColB
200911  46643,47
200912  810581,018
201001  131079,361

Does anyone have any idea?

  • What is the data type of the Colb column?

1 answer

8

Use a GROUP BY together with the SUM()

SELECT ColA, SUM(ColB)
FROM tabela
GROUP BY ColA;
  • Thank you very much !!

  • @Andretovar if the answer has solved your problem, mark it as answered. Do a [tour] and learn more about it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.