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
 Transact-SQL (2000)
 SQL Server Query

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-02-27 : 12:10:55
krishna writes "We have three tables doctortbl,patienttbl,patientdatatbl.
In doctortbl colmns like city,doctorid...etc,patienttbl colmns like
patientid,doctorid....etc and in Patientdatatbl colmns like
patientid,unitstaken... etc.

Now we have to display city,total no of doctors,total no of patients and total unitstaken.In this we want to display each city wise how many doctors are there ,how many patients are there to those doctors in each city,and how many units taken from patients
whose are belongs to those doctors .

We want to display all the city wise Split"

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-02-27 : 16:24:03
I think this is what u want

Select city, count(d.doctorid) as [# of DRs] from doctortbl group by city

Select d.city, count(p.patientid) from doctortbl d
inner join patienttbl p on d.doctorid = p.doctorid
group by d.city

Select d.city, count(p.unitstaken) from doctortbl d
inner join patienttbl p on d.doctorid = p.doctorid
group by d.city
Go to Top of Page
   

- Advertisement -