日期:2014-05-18 浏览次数:20676 次
select day(ghrq),count(djh) as sl,max('初诊')as xm from gh_sfdj where ctbz='0' and cf='0' group by day(ghrq)
union select day(rq),count(id) as sl,max('咨询') as xm from t_czdhlyb where bz='0' group by day(rq)
union select day(rq),count(id) as sl,max('留诊')as xm from t_czdhlyb where bz='0' and sflz='0' group by day(rq)
union select day(rq),sum(case sflz='0' then 1 else 0 end)*100/count(id) as sl,max('比例')as xm
from t_czdhlyb where bz='0' group by day(rq)
------解决方案--------------------
select day(ghrq),count(djh) as sl,max('初诊')as xm, 0 as col
from gh_sfdj
where ctbz='0' and cf='0'
group by day(ghrq)
union
select day(rq),count(id) as sl,max('咨询') as xm ,count(1) * 100/(select count(id) from t_czdhlyb where rq = a.rq and bz='0' and sflz='0')
from t_czdhlyb a
where bz='0'
group by day(rq)
union
select day(rq),count(id) as sl,max('留诊')as xm ,count(1) * 100/(select count(id) from t_czdhlyb where rq = a.rq and bz='0' )
from t_czdhlyb
where bz='0' and sflz='0'
group by day(rq)