首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

还是UNION 有关问题,

2012-01-09 
还是UNION 问题,急select ghrq as rq,count(djh) as sl,max(初诊)as xm from gh_sfdj where ctbz0 an

还是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 ) bwhere a.rq=b.rq 

热点排行
Bad Request.