select GY_YGDM.YGXM as 医生姓名, SUM(CASE GY_SFXM.SFXM WHEN '1' THEN MS_SFMX.ZJJE ELSE 0 END) 西药, SUM(CASE GY_SFXM.SFXM WHEN '4' THEN MS_SFMX.ZJJE ELSE 0 END) 卫材费, SUM(CASE GY_SFXM.SFXM WHEN '5' THEN MS_SFMX.ZJJE ELSE 0 END) 挂号费, SUM(CASE GY_SFXM.SFXM WHEN '3' THEN MS_SFMX.ZJJE ELSE 0 END) 草药, SUM(CASE GY_SFXM.SFXM WHEN '2' THEN MS_SFMX.ZJJE ELSE 0 END) 成药, SUM(CASE GY_SFXM.SFXM WHEN '19' THEN MS_SFMX.ZJJE ELSE 0 END) 诊查费, SUM(CASE GY_SFXM.SFXM when '13' THEN MS_SFMX.ZJJE ELSE 0 END) 化验费, SUM(CASE GY_SFXM.SFXM WHEN '21' THEN MS_SFMX.ZJJE ELSE 0 END) 材料费, SUM(CASE GY_SFXM.SFXM WHEN '22' THEN MS_SFMX.ZJJE ELSE 0 END) 麻醉费, SUM(CASE GY_SFXM.SFXM WHEN '25' THEN MS_SFMX.ZJJE ELSE 0 END) 护理费, SUM(CASE WHEN GY_SFXM.SFXM IN ('26' ,'12') THEN MS_SFMX.ZJJE ELSE 0 END) 放射费, SUM(CASE WHEN GY_SFXM.SFXM IN ('9' ,'15','20') THEN MS_SFMX.ZJJE ELSE 0 END) 检查费, SUM(CASE GY_SFXM.SFXM WHEN '24' THEN MS_SFMX.ZJJE ELSE 0 END) 手术费, SUM(CASE GY_SFXM.SFXM WHEN '7' THEN MS_SFMX.ZJJE ELSE 0 END) 床位费, SUM(CASE GY_SFXM.SFXM WHEN '10' THEN MS_SFMX.ZJJE ELSE 0 END) 超声费, SUM(CASE GY_SFXM.SFXM WHEN '16' THEN MS_SFMX.ZJJE ELSE 0 END) 心电图费, SUM(CASE WHEN GY_SFXM.SFXM IN ('11' ,'14','18','6' ) THEN MS_SFMX.ZJJE ELSE 0 END) 治疗费, SUM(CASE WHEN GY_SFXM.SFXM IN ('8' ,'17','23') THEN MS_SFMX.ZJJE ELSE 0 END) 其他费, SUM(MS_SFMX.ZJJE) 费用合计 from MS_GHMX inner join GY_YGDM on GY_YGDM.YGDM = MS_GHMX.YSDM inner join MS_MZXX on MS_MZXX.BRID = MS_GHMX.BRID left join MS_SFMX on MS_SFMX.MZXH=MS_MZXX.MZXH left join GY_SFXM on GY_SFXM.SFXM=MS_SFMX.SFXM where MS_GHMX.GHSJ >= '2015-01-01'--:开始时间 and MS_GHMX.GHSJ < '2015-01-25'--:结束时间 group BY GY_SFXM.SFXM, GY_YGDM.ygxm
结果: