现在一个表里的数据是这样子的:
字段1 字段2 字段3 字段4 字段5 字段6
记录1 a b 1
记录2 a b 2
记录3 a b 3
记录4 c d 4
记录5 c d 5
记录6 c d 6
记录6 c d 7
现在我显示成如下这样子: 字段1 字段2 字段3 字段4 字段5 字段6
记录1 a b 1 2 3
记录2 c d 4 5 6 7
可以用一条sql(Oracle)语句搞定吗?
字段1 字段2 字段3 字段4 字段5 字段6
记录1 a b 1
记录2 a b 2
记录3 a b 3
记录4 c d 4
记录5 c d 5
记录6 c d 6
记录6 c d 7
现在我显示成如下这样子: 字段1 字段2 字段3 字段4 字段5 字段6
记录1 a b 1 2 3
记录2 c d 4 5 6 7
可以用一条sql(Oracle)语句搞定吗?
select A1.字段1,A1.字段2,A1.字段3,A2.字段4,A3.字段5,A4.字段6
from
(select 字段1,字段2,字段3
from table
where not 字段3 is null) A1
full join
(select 字段1,字段2,字段4
from table
where not 字段4 is null) A2 on (A1.字段1=A2.字段1 and A1.字段2=A2.字段2)
full join
(select 字段1,字段2,字段5
from table
where not 字段5 is null) A3 on (A1.字段1=A3.字段1 and A1.字段2=A3.字段2)
full join
(select 字段1,字段2,字段6
from table
where not 字段6 is null) A4 on (A1.字段1=A4.字段1 and A1.字段2=A4.字段2)
sum(字段4) as '字段4',
sum(字段5) as '字段5',
sum(字段6) as '字段6'
from tb
group by 字段1,字段2;
from
(select 字段1,字段2,sum(字段3) as '字段3',
sum(字段4) as '字段4',
sum(字段5) as '字段5',
sum(字段6) as '字段6'
from tb
group by 字段1,字段2) a;
from tb
group by 字段1,字段2