SQL Query Clarification

前端 未结 4 620
耶瑟儿~
耶瑟儿~ 2021-01-23 20:37

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:

4条回答
  •  失恋的感觉
    2021-01-23 20:59

    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; 
    

提交回复
热议问题