Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
krishna writes "We have three tables doctortbl,patienttbl,patientdatatbl.In doctortbl colmns like city,doctorid...etc,patienttbl colmns likepatientid,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 citySelect d.city, count(p.patientid) from doctortbl dinner join patienttbl p on d.doctorid = p.doctoridgroup by d.citySelect d.city, count(p.unitstaken) from doctortbl dinner join patienttbl p on d.doctorid = p.doctoridgroup by d.city