creaet table tmp_cs1
nologging as
select a.subsid,
a.yxplanid,
a.yxplanname,
row_number() over (partition by a.subsid order by a.yxplanid) rn
from tmp_cs a
where 1=1;
select a.subsid from tmp_cs1 a group by a.susid having count(*)>1;
select b.susid,
/* 转换语句*/
max(decode(b.rn,1,trim(b.yxplanname),null))||max(decode(b.rn,2,','||trim(b.yxplanname),null))) new
from tmp_cs1 group by b.subsid
常用做报表语句:
select a.subsid,
sum(case when validbillcnt=201001000 then a.amt esle 0 end) as amt10,
sum(case when validbillcnt=201001100 then a.amt esle 0 end) as amt11
from tmp_tb0 a
group by a.subsid