select 'JHCIS OP visit' as 'i',count(distinct v.visitno) as 'all_visits' 
from visit v 
inner join visitdiag d on d.visitno=v.visitno
where substr(d.diagcode,1,1)!='Z' 
and v.visitdate<=substr(v.dateupdate,1,10) 
and v.visitdate between '2014-10-01' and '2015-04-30' 
group by (visitdate is not null)
union
select 'JHCIS OP คีย์เสร็จในวัน' as 'i'
,count(distinct (if(v.visitdate=substr(v.dateupdate,1,10),v.visitno,null))) as 'in_day' 
from visit v 
inner join visitdiag d on d.visitno=v.visitno
where substr(d.diagcode,1,1)!='Z' 
and v.visitdate<=substr(v.dateupdate,1,10) 
and v.visitdate between '2014-10-01' and '2015-04-30' 
group by (visitdate is not null)