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)
 get results from other fields when using aggregate function

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2000-11-05 : 22:35:38
Mark McAdam writes "I am having trouble understanding how to use an aggregate function and use the results of the aggregation to find more results.

eg.

I have three tables
A ( id, status, qty)
(id is primary key)
B ( id, price, cid)
(multiple records for each id, cid and id is primary key)
C ( cid, cname)
( cid is primary key)

I want to find the cname with the sum of qty for the min(price)

select sum(qty), min(price), cname
from a
right join b on (a.id = b.id)
join c on (b.cid = c.cid)
where a.status = 'OK'
and b.price > 0
group by ???

Can it be done in one SQL statement, or should i just use two.

Thanks"
   

- Advertisement -