Solved

How would i get multiple sum of rows in one query?

Posted on 2006-10-24
3
214 Views
Last Modified: 2006-11-18
How would I, structure a query so that i could get back multiply row sums?

This is what i have:

SELECT  SUM(T1) as Total
FROM table name

What i need is SUM of T2 and T3 also and Then add up T1,T2, and T3 as a table named GTotal

Thanks for any help!
0
Comment
Question by:bmanmike39
3 Comments
 
LVL 92

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 150 total points
ID: 17800477
Hi bmanmike39,

Not sure what you're after, but you could do something like:

SELECT SUM(Column1) AS Total1, SUM(Column2) AS Total2, SUM(Column3) AS Total3
FROM SomeTable

Regards,

Patrick
0
 
LVL 6

Assisted Solution

by:Gokulm
Gokulm earned 150 total points
ID: 17801021
If the table GTotal is already present you could use the below query

INSERT GTotal SELECT 'field1', SUM(T1) + SUM(T2) + SUM(T3), 'field3' FROM tablename

If the table GTotal is to be created with this sum you could use the below query

SELECT 'field1' AS 'name1', SUM(T1) + SUM(T2) + SUM(T3) AS 'Total', 'field3' AS 'descr' INOT GTotal  FROM tablename
0
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 200 total points
ID: 17801222
select sum(T1), sum(T2), sum(T1+T2)  as GTotal from TABLE1

U can do it in one query, instead of using a table
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
export sql results to csv 6 36
Webservices in T-SQL 3 31
What is the proper way to use for criteria in left join? 7 27
SQL server vNext 18 29
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

777 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