Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

performance with data link

Status
Not open for further replies.

raji96

Programmer
Aug 7, 2001
64
0
0
US
I have a query which is in a loop and is like this

select sum(a.time),sum(a.cost)
from a,b
where b.rid=10
and a.id=2
and a.id=b.id

The problem is we are connecting to the database via data link and is talking time to get connected,for eg 2 sec to connect and the loop can go only for 10 parts, so 20secs for connection alone.
So we are thinking of in clause instead of loop, but not sure how to sum it, since the data is like this

rid id time cost
10 2 20 200
10 5 20 100
9 6 100 100
10 2 50 400
10 5 10 50
10 5 10 100

My result should look like for a.id=2
70 600
My result should look like for a.id=5
40 250
My result should look like for a.id=6
100 100

When i use 'in'(a.id in(2,5,6) clause in the same query the result is
210, 950

I can understand what the query is doing but not sure how to get the desire result.

Please help !
Thanks!
 
If I understand what you are trying to do, see if this helps:

select a.id, sum(a.time),sum(a.cost)
from a,b
where b.rid=10
and a.id IN (2,5,6)
and a.id=b.id
GROUP BY a.id;

Elbert, CO
1747 MST
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top