select a.pdx,count(a.pdx) as pdx_count ,i.name as icdname ,sum(income) as sum
from vn_stat a
left outer join icd101 i on i.code=a.main_pdx
where a.vstdate between '2014-10-01' and '2015-09-30'
and a.pdx<>'' and a.pdx is not null
group by a.pdx,i.name
order by sum(income) desc
select pdx,name ,count(an),sum(income)/count(an),sum(income) as sumtotal
from an_stat a,icd101 i
where a.dchdate between '2014-10-01' and '2015-09-30'
and a.pdx = i.code
group by pdx
order by sumtotal desc