日期:2014-05-18  浏览次数:20452 次

还是UNION 问题,急
select ghrq as rq,count(djh) as sl,max('初诊')as xm from gh_sfdj where ctbz='0' and cf='0' group by ghrq 
union select yf_ckdj.rq,count(yf_ckdj.djh) as sl,max('化验人数') as xm from yf_ckdj,xt_sffm where yf_ckdj.fpxm=xt_sffm.bm and xt_sffm.mc like '%化验%' group by yf_ckdj.rq

怎么加个 化验人数/初诊的比率 也是作为 xm

------解决方案--------------------
select cast(化验人数*100/初诊 as nvarchar(20))+'%' as xm
------解决方案--------------------
2/3 显示成字符串,还是66.67%
------解决方案--------------------
SQL code
select ghrq as rq,count(djh) as sl,max('初诊')as xm from gh_sfdj 
where ctbz='0' and cf='0' group by ghrq  
union select yf_ckdj.rq,count(yf_ckdj.djh) as sl,max('化验人数') as xm from yf_ckdj,xt_sffm 
where yf_ckdj.fpxm=xt_sffm.bm and xt_sffm.mc like '%化验%' group by yf_ckdj.rq 
union select a.rq,case when a.sl=0 then -1 else b.sl/a.sl end as sl,
        '化验人数/初诊' as xm 
from 
(select ghrq as rq,count(djh) as sl from gh_sfdj 
where ctbz='0' and cf='0' group by ghrq ) a,
 (select yf_ckdj.rq,count(yf_ckdj.djh) as sl from yf_ckdj,xt_sffm 
where yf_ckdj.fpxm=xt_sffm.bm and xt_sffm.mc like '%化验%' group by yf_ckdj.rq ) b
where a.rq=b.rq