Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

SQL View that SUMs columns

Posted on 2013-11-13
3
333 Views
Last Modified: 2013-11-13
I have a table that has ID numbers and financial transactions that I am trying to sum together. Basically I want to turn this:-

1  |  100  |  200  |  500
2  |  200  |  400  |  800
1  |  400  |  200  |  100
3  |  100  |  200  |  100
3  |  500  |  200  |  400

into this:-

1  |  500  |  400  |  600
2  |  200  |  400  |  800
3  |  600  |  400  |  500

..using a SQL view under SQL 2005. Is this possible and can someone advise on the best way to make it happen?

Thanks
0
Comment
Question by:steven_gould
3 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 300 total points
ID: 39645220
You want something along the lines of the following (modified for your table and column names obviously):
SELECT ColA, SUM(ColB), SUM(ColC), SUM(ColD)
FROM YourTable
GROUP BY ColA

Open in new window

0
 
LVL 65

Assisted Solution

by:Jim Horn
Jim Horn earned 200 total points
ID: 39645224
Need you to tell us the column names we're talking about, but in air code...
CREATE VIEW vw_name_me AS

-- Write some code comments  here. 

SELECT id, SUM(Column1), SUM(Column2), SUM(Column3)
FROM Yourtable
GROUP BY id
ORDER BY id
GO

Open in new window

Also, here's a tutorial on SQL Server GROUP BY Solutions that will help understand grouping concepts.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question