51
แจ้งปัญหา / ขอความช่วยเหลือ / Re: ขอคำแนะนำ SQL หน่อยครับ
« เมื่อ: มิถุนายน 04, 2014, 12:42:49 PM »
select v.pttype,count(v.vn) as vn,count(distinct v.hn) as hn,sum(v.income) as income,p.name
from (select vn from dtmain
where vstdate between "2014-01-01" and "2014-05-31"
and vsttime > "16:00:00"
group by vn) d
left join vn_stat v on d.vn=v.vn
left join pttype p on v.pttype=p.pttype
group by v.pttype
from (select vn from dtmain
where vstdate between "2014-01-01" and "2014-05-31"
and vsttime > "16:00:00"
group by vn) d
left join vn_stat v on d.vn=v.vn
left join pttype p on v.pttype=p.pttype
group by v.pttype