Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Return single table based on results of two select statements

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-09-20 : 23:21:49
Alex writes "Hello, would like to seek your advice on the following issue:

I have a table like such:

 
TIMESTAMP UNIT_ID COMPONENT_ID OPERATIONS RUNTIME
{timestamp} Unit1 Comp1 5 700
{timestamp} Unit1 Comp2 6 300
{timestamp} Unit2 Comp1 7 1700
{timestamp} Unit2 Comp2 8 2700
{timestamp+1} Unit1 Comp1 9 6200
{timestamp+1} Unit1 Comp2 4 100
{timestamp+1} Unit2 Comp1 3 2300
{timestamp+1} Unit2 Comp2 5 1800


What I wish to return is:

Sum of RUNTIME for all COMPONENT_ID=Comp1 as SUM1
Sum of RUNTIME for all COMPONENT_ID=Comp2 as SUM2

What I can do:
At present I only know of how to return one of the above. I have tried declaring integers to hold summations, but I couldn't get this to work.

What I am seeking:
The general idea of what I want is as follows...

 
SELECT totalC1, totalC2 from
(
SELECT SUM(runtime) as totalC1 where COMPONENT_ID=Comp1
JOIN
SELECT SUM(runtime) as totalC2 where COMPONENT_ID=Comp2
)


 
RETURNING:
TOTALC1 TOTALC2
10900 4900


Oh, and I don't want to have to do this is a stored procedure - but rather a direct SQL query... ideally ;o}

Hope you can help!"
   

- Advertisement -