?
Solved

SQL View that SUMs columns

Posted on 2013-11-13
3
Medium Priority
?
344 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
[X]
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
3 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 1200 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 66

Assisted Solution

by:Jim Horn
Jim Horn earned 800 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 Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
In this article, we’ll look at how to deploy ProxySQL.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

752 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