SELECT (LEFT(visit.visitdate,4)+543)  YEAR 
,sum(case when (substr(visitdate,1,10)<>substr(dateupdate,1,10) )
then 1 else 0 end) as nononestopservice
,sum(case when (substr(visitdate,1,10)= substr(dateupdate,1,10) )
then 1 else 0 end) as onestopservice
,COUNT(pid) as 'ทั้งหมด'
,ROUND(SUM(CASE WHEN(substr(visitdate,1,10)= substr(dateupdate,1,10))
then 1 else 0 end)*100/(sum(case when (substr(visitdate,1,10)<>substr(dateupdate,1,10) )
then 1 else 0 end)+sum(case when (substr(visitdate,1,10)= substr(dateupdate,1,10) )
then 1 else 0 end)),2) as 'ผลงานร้อยละ'
FROM visit
GROUP BY YEAR
ORDER BY visit.visitdate DESC;