set @ds1:='2013-10-1',@ds2:='2014-9-30';
select 'รายวัน' type,round(avg(opd)) OPD,round(avg(ipd)) IPD
from (select (a.date) MyGroup,sum(type='OPD') OPD,sum(type='IPD') IPD
from (select o.vstdate date,o.vn,o.hn,null as an,'OPD' type
from ovst o
where o.vstdate between @ds1 and @ds2
union all
select i.regdate,null as vn,i.hn,i.an,'IPD' type
from ipt i
where i.regdate between @ds1 and @ds2) a
group by MyGroup) a