SELECT cast("dept_id" as varchar(32)) , cast("dept_name" as varchar(30)) AS "病区", "total_surgical_patients" AS "手术总数", "total_preop_medication_patients" AS "用药总数", "total_discharged_patients" AS "出院总数", CASE WHEN "total_surgical_patients" = 0 THEN NULL ELSE ROUND(("total_preop_medication_patients"/NULLIF("total_surgical_patients", 0))*100, 2)::varchar(20) END AS "按所在科室用药率%", CASE WHEN "total_discharged_patients" = 0 THEN NULL ELSE ROUND(("total_preop_medication_patients"/NULLIF("total_surgical_patients", 0))*100, 2)::varchar(20) END AS "按出院科室用药率%", cast("dept_parentcode" as varchar(40)) FROM "RemoteData"."fn_getantidruguse_surgery"('2021/3/1', '2024/3/30', 'preoperative_medication', ' and 1=1 ') order by "dept_id"
出现摸不着头脑的问题,是分母异常自动屏蔽处理了,导致计算百分数是0。因此需要检查分母NULLIF()
标签:medication,varchar,百分数,surgical,dept,patients,pg,计算,total From: https://www.cnblogs.com/usegear/p/18105801