Solved

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

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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.

746 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

15 Experts available now in Live!

Get 1:1 Help Now