select t.unitid,t.unitname,j1,j2,j3,j4,j5,j6,j7,j8,j9,j10,j11,j12,j13 from
(select unitid,count(*) as j1 from
(select rpad(userid,6,'0')||'000000' as unitid ,spec from tbltechman)
where spec='01' group by unitid) a,
(select unitid,count(*) as j2 from
(select rpad(userid,6,'0')||'000000' as unitid ,spec from tbltechman)
where spec='02' group by unitid) b,
(select unitid,count(*) as j3 from
(select rpad(userid,6,'0')||'000000' as unitid ,spec from tbltechman)
where spec='03' group by unitid) c,
(select unitid,count(*) as j4 from
(select rpad(userid,6,'0')||'000000' as unitid ,spec from tbltechman)
where spec='04' group by unitid) d,
(select unitid,count(*) as j5 from
(select rpad(userid,6,'0')||'000000' as unitid ,spec from tbltechman)
where spec='05' group by unitid) e,
(select unitid,count(*) as j6 from
(select rpad(userid,6,'0')||'000000' as unitid ,spec from tbltechman)
where spec='06' group by unitid) f,
(select unitid,count(*) as j7 from
(select rpad(userid,6,'0')||'000000' as unitid ,spec from tbltechman)
where spec='07' group by unitid) g,
(select unitid,count(*) as j8 from
(select rpad(userid,6,'0')||'000000' as unitid ,spec from tbltechman)
where spec='08' group by unitid) h,
(select unitid,count(*) as j9 from
(select rpad(userid,6,'0')||'000000' as unitid ,spec from tbltechman)
where spec='09' group by unitid) i,
(select unitid,count(*) as j10 from
(select rpad(userid,6,'0')||'000000' as unitid ,spec from tbltechman)
where spec='10' group by unitid) j,
(select unitid,count(*) as j11 from
(select rpad(userid,6,'0')||'000000' as unitid ,spec from tbltechman)
where spec='11' group by unitid) k,
(select unitid,count(*) as j12 from
(select rpad(userid,6,'0')||'000000' as unitid ,spec from tbltechman)
where spec='12' group by unitid) l,
(select unitid,count(*) as j13 from
(select rpad(userid,6,'0')||'000000' as unitid ,spec from tbltechman)
where spec='13' group by unitid) m,
(select unitid,unitname from tblunit where unitid like '5227%000000' order by unitid) t
where t.unitid=a.unitid(+) and t.unitid=b.unitid(+) and t.unitid=c.unitid(+) and t.unitid=d.unitid(+)
and t.unitid=e.unitid(+) and t.unitid=f.unitid(+) and t.unitid=g.unitid(+) and t.unitid=h.unitid(+)
and t.unitid=i.unitid(+) and t.unitid=j.unitid(+) and t.unitid=k.unitid(+) and t.unitid=l.unitid(+)
and t.unitid=m.unitid(+)
order by unitid