select k.department ,k.depcode,count(o.hn)as cc,sum(v.income) as tt
from ovst o,kskdepartment k,opitemrece op,vn_stat v
where o.vstdate between '2007-01-01' and '2007-01-30'
and o.main_dep in ('120','010','020','014','050','080','070','060','011','110','108','121','041','040','032','051','091','043','029','039')
and o.main_dep = k.depcode
and o.hn = op.hn
and o.hn = v.hn
group by k.department
order by cc
ขอบคุณคับ