select o.vstdate
,sum(sum_price) 'total'
,sum(if(paidst='00',sum_price,0)) 'Paidst00'
,sum(if(paidst='01',sum_price,0)) 'Paidst01'
,sum(if(paidst='02',sum_price,0)) 'Paidst02'
,sum(if(paidst='03',sum_price,0)) 'Paidst03'
,sum(if(paidst='04',sum_price,0)) 'Paidst04'
from opitemrece o
where vstdate between '2012-10-1' and '2012-10-31'
and vn is not null
group by vstdate
***ดูตาราง PAIDST ประกอบ***