select jsta.jh, sum(case when jsta.sgzyxm='完井作业' then jsta.sjts else 0 end ) as wjzq, sum(jsta.sjts)-sum(case when jsta.sgzyxm='完井作业' then jsta.sjts else 0 end ) as zjzq FROM JSTA jsta
where jsta.jd1 is not null or jsta.jd2 is not null
(select jsta.jh,
sum(case when jsta.sgzyxm = '完井作业' then jsta.sjts else 0 end) as wjzq,
sum(jsta.sjts) - sum(case when jsta.sgzyxm = '完井作业' then jsta.sjts else 0 end) as zjzq
FROM JSTA jsta
where jsta.jd1 is not null
or jsta.jd2 is not null
group by jsta.jh) zjzq
on zjzq.jh=a.jh
on zjzq.jh = a.jh
left join ( select jh,count(*) as kc from jsdb where tgcc not like '%导管%'
group by jh )kc
on a.jh=kc.jh
left join (select jh, count(*) as kc
from jsdb
where tgcc not like '%导管%'
group by jh) kc
on a.jh = kc.jh
WHERE
ABS(a.jdhzb - #{jdhzb}) < #{jl} -- 按井底坐标选
AND
ABS(a.jdzzb - #{jdzzb}) < #{jl}
WHERE 1 = 1
and a.jh not like '%侧%'
and ABS(a.jdhzb - #{jdhzb}) < #{jl} -- 按井底坐标选
AND ABS(a.jdzzb - #{jdzzb}) < #{jl}
and TO_CHAR(b.wjrq, 'YYYY') between #{wjsjks} and #{wjsjjs}
order by jdjl asc
) where ROWNUM < =5 ) a order by jh
</select>
<!-- select ss.kc,ss.ztxh,ss.cc,-->
<!-- count( *) as ztsl,-->
<!-- round( sum(case when ss.kc=1 and tcyk=1 then 1 else 0 end )/count(*)*100,2)as ytzl,-->
<!-- round( sum(case when ss.kc=2 and tcyk=1 then 1 else 0 end )/count(*)*100,2) as etzl,-->
<!-- round( sum(case when ss.kc=3 and tcyk=1 then 1 else 0 end )/count(*)*100,2) as stzl,-->
<!-- round( sum(case when ss.kc=4 and tcyk=1 then 1 else 0 end )/count(*)*100,2) as sitzl,-->
<!-- round( sum(case when ss.kc=5 and tcyk=1 then 1 else 0 end )/count(*)*100,2) as wtzl-->