17,141
社区成员




select id,
a.gdl 本月供电量,
a.sdl 本月售电量,
b.gdl 上月供电量,
b.sdl 上月售电量
from (select id, rq, gdl, sdl from tablename) a,
(select id, rq, gdl, sdl from tablename) b
where a.id = b.id
and add_months(to_date(b.rq, 'yyyymm'), 1) = to_date(a.rq, 'yyyymm');
from(
select
id,
sum(decode(rq,200808,gdl,0)) 本月供,
sum(decode(rq,200808,sdl,0)) 本月售,
sum(decode(rq,200807,gdl,0)) 上月供,
sum(decode(rq,200807,sdl,0)) 上月售,
round((sum(decode(rq,200808,gdl,0)) -sum(decode(rq,200808,sdl,0)) )/sum(decode(rq,200808,gdl,0)),4) loss_rate
from table
group by id
order by 6 desc
)
where rownum<=20