Solved

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

Posted on 2006-10-24
3
215 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to prevent deleting SQL tables thru FE Application? 20 86
SQL Pivot with row total 5 27
sql server query 12 26
Compare a numeric value to a varchar w/o getting an error 4 21
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
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.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

861 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