I have two tables doctor and billing. I wish to view the dname,doctorid and sum(fees) of doctors treating more than one patient.
doctor table columns are as follows:
Try this
SELECT d.dname,b.doctorid,Sum(b.fees)as "TotalFees" FROM billing b inner join doctor d ON b.doctorid=d.doctorid GROUP BY d.dname,b.doctorid HAVING count(b.patientid)>1;