679
社区成员
发帖
与我相关
我的任务
分享
select n.deriveno,
n.appno,
m.ride_starttime,
max(decode(c.stagecode, '4', c.mileage, null)) mileage1,
max(decode(c.stagecode, '7', c.mileage, null)) mileage2
from app_send s, app_nomapping n, app_main m, app_carstatus c
where s.deriveno = n.deriveno
and n.optype = 'CMB'
and n.appno = m.appno
and s.deriveno = c.deriveno
and n.appno not in (select r.deriveno from app_ridecost r)
group by n.deriveno, n.appno, m.ride_starttime
order by n.deriveno, m.ride_starttime
select deriveno,appno,ride_starttime, decode(rn,1,mileage1,mileage2) as mileage
from (select deriveno,appno, ride_starttime,mileage1,mileage2,row_number()over(partition by deriveno order by ride_starttime) rn
from (select n.deriveno,
n.appno,
m.ride_starttime,
max(decode(c.stagecode, '4', c.mileage, null)) mileage1,
max(decode(c.stagecode, '7', c.mileage, null)) mileage2
from app_send s, app_nomapping n, app_main m, app_carstatus c
where s.deriveno = n.deriveno
and n.optype = 'CMB'
and n.appno = m.appno
and s.deriveno = c.deriveno
and n.appno not in (select r.deriveno from app_ridecost r)
group by n.deriveno, n.appno, m.ride_starttime
)
);