Solved

SQL View that SUMs columns

Posted on 2013-11-13
3
322 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
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.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

896 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now