Solved

SQL View that SUMs columns

Posted on 2013-11-13
3
320 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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

772 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

11 Experts available now in Live!

Get 1:1 Help Now