Solved

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

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server for XML PATH giving wrong results. 6 59
Remove () 10 40
What are the recommended security measures to put in place? 19 91
mssql 7 32
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.
Viewers will learn how the fundamental information of how to create a table.

732 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