Solved

SQL View that SUMs columns

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

730 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