[sql]
代碼如下:
create table wlbtest1(
username varchar2(2),
deptID number
);
create table wlbtest2(
deptName varchar2(10),
deptID number
);
insert into wlbtest1 values ('a', 1);
insert into wlbtest1 values ('b', 1);
insert into wlbtest1 values ('c', 1);
insert into wlbtest1 values ('d', 2);
insert into wlbtest1 values ('e', 2);
insert into wlbtest1 values ('f', 2);
insert into wlbtest2 values ( '部門1' ,1);
insert into wlbtest2 values ( '部門2', 2);
select deptID, wm_concat(username) username,'部門'||deptID deptName from wlbtest1 group by deptID
執行結果: