表15
a1 a2
1 a
1 b
2 x
2 y
2 z
用select能显示成以下结果吗?
1 ab
2 xyz
------解决方案--------------------
ORACLE10G
- SQL code
CREATE TABLE a(a1 INT, a2 VARCHAR2(1));INSERT INTO a VALUES(1,'a');INSERT INTO a VALUES(1,'b');INSERT INTO a VALUES(2,'x');INSERT INTO a VALUES(2,'y');INSERT INTO a VALUES(2,'z');select a1, replace(wmsys.wm_concat(a2),',','') a2 from a group by a1
------解决方案--------------------
- SQL code
with tb(a1,a2) as (select 1,'a' from dualunionselect 1,'b' from dualunionselect 2,'x' from dualunionselect 2,'y' from dualunionselect 2,'z' from dual)select a1,replace(wm_concat(a2),',') as ass from tb group by a1/ A1 ASS---------- ---------- 1 ab 2 xzySQL>
------解决方案--------------------
列转行问题