how to use sql join in mysql

前端 未结 4 1089
礼貌的吻别
礼貌的吻别 2021-01-23 07:33

table name: tbl_schedule

tr_id(P.K.)  mr_id(F.K.)   sch_date   doctor_id   
-----------  -----------   --------   ----------
1              23         01/01/2012         


        
4条回答
  •  太阳男子
    2021-01-23 08:26

    First of all u make sure that you have defined sch_date as DATE type AND Database engine should be InnoDb

    then it is easy to fetch data as per your question

    QUERY

    SELECT T2.mr_id,T2.mr_fname,T2.mr_lname,COUNT(doctor_id) FROM tbl_schedule AS T1 INNER JOIN tbl_user AS T2 ON T1.mr_id = T2.mr_id WHERE T1.sch_date > 'date1' AND T1.sch_date < 'date2' GROUP BY doctor_id HAVING COUNT(doctor_id) > 0 
    

提交回复
热议问题