如果你的 1类 2类 3类
是数值类型的话,可以这样
select id, sum(1类),sum(2类),sum(3类)
from (
select id, 1类 ,0,0 from
tab_1 where lx=1类
union all
select id, 0,2类,0 from
tab_1 where lx=2类
union all
select id, 0 ,0,3类 from
tab_1 where lx=3类
) as temp
group by id
是数值类型的话,可以这样
select id, sum(1类),sum(2类),sum(3类)
from (
select id, 1类 ,0,0 from
tab_1 where lx=1类
union all
select id, 0,2类,0 from
tab_1 where lx=2类
union all
select id, 0 ,0,3类 from
tab_1 where lx=3类
) as temp
group by id
(select sj from tab_l a where a.id=b.id and lx='2类') as 2类,
(select sj from tab_l a where a.id=b.id and lx='3类') as 3类
from tab_l b
(select sj from tab_l a where a.id=b.id and lx='2类') as 2类,
(select sj from tab_l a where a.id=b.id and lx='3类') as 3类
from tab_l b
max(decode(lx,'2类',sj)) 2类,
max(decode(lx,'3类',sj)) 3类
from tab_1
group by id;
max(decode(lx,'2类',sj)) 2类,
max(decode(lx,'3类',sj)) 3类
from tab_1
group by id;
max(decode(lx,'2类',sj)) 2类,
max(decode(lx,'3类',sj)) 3类
from tab_1
group by id;