CREATE OR REPLACE Procedure SP_GETSUMMARY_SUCKERROD(well in varchar2,kgsj in varchar2,p_cursor out ego.cursorType)
as
begin
open p_cursor for
select a.JH,a.KGRQ,replace(decode(a.XH,'',MC,a.XH),'HS','活塞')as xh,MC,b.SD,GG,CD,XJRQ,
CJ,TYRQ,GHBS,CJDM,LX,
SCCJ , GJ , KX , FZQSL , FZQLX , BZ ,LWLX, DM from (
select decode(xh1,'',xh,xh1) as xh,JH,KGRQ,SD from (
select (case when xh in (select min(to_number(xh)) as xh from ddb041 where
jh=well and KGRQ=to_date(kgsj,'yyyy-mm-dd') group by GG ) then 'φ'||GG end)as xh1,
xh ,GG,JH,KGRQ,SD
from ddb041 where jh=well and KGRQ=to_date(kgsj,'yyyy-mm-dd')
group by gg,JH,KGRQ,SD, XH
order by sd
))a,ddb041 b where a.jh=b.jh and a.KGRQ=b.Kgrq and a.sd=b.sd order by a.sd;
end;