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)
 retriving parent column when i use sum()

Author  Topic 

Radhiga
Starting Member

35 Posts

Posted - 2006-04-07 : 05:52:56
i have company table.
companyid cname
1 Company1
2 Company2
3 Company3

tbl_reseller

Reserller_id Resller_name company_id
1 R1 1
2 R2 1


Reseller_Sales
Reseller_id Sales
1 100
2 500

now i need to get the following reslut...is it possible to achieve in single query without using temp table or function...help pls
1 Company1 R1 600

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-04-07 : 06:01:17
like this ?
select c.companyid, c.cname, sum(s.Sales)
from company c inner join tbl_reseller r
on c.companyid = r.company_id
inner join Reseller_Sales s
on r.Reseller_id = s.Reseller_id
gropu by c.companyid, c.cname




KH


Go to Top of Page

Radhiga
Starting Member

35 Posts

Posted - 2006-04-07 : 06:10:08
Hai Thanks for the Immediate Reply. In my actual query i cannot use group by cname, b'coz i haave lot of colums from the parent table.
i just sent u the sample table...
im not sure is it possible
quote:
Originally posted by khtan

like this ?
select c.companyid, c.cname, sum(s.Sales)
from company c inner join tbl_reseller r
on c.companyid = r.company_id
inner join Reseller_Sales s
on r.Reseller_id = s.Reseller_id
gropu by c.companyid, c.cname




KH




Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-04-07 : 06:28:08
You can post your table structure here with more sample data and the result that you want.



KH


Go to Top of Page
   

- Advertisement -