I use SQL to simulate data with similar categories:
select TA.leaderCD, TA.EmpCD, TA.message
from
(select '1001' as EmpCD, 'L001' as leaderCD,'M1' as message
union
select '1001','L002','M1'
union
select '1001', 'L003','M1'
union
select '1002', 'L001','M1'
union
select '1002', 'L002','M2'
union
select '1002', 'L004','M2'
union
select '1003', 'L002','M1'
union
select '1003', 'L003','M1'
union
select '1003', 'L005','M2'
union
select '1004', 'L002','M1'
union
select '1004', 'L003','M2'
union
select '1004', 'L004','M2'
union
select '1004', 'L005','M3') as TA
order by
TA.leaderCD
The result is:
leaderCD EmpCD message
L001 1001 M1
L001 1002 M1
L002 1001 M1
L002 1002 M2
L002 1003 M1
L002 1004 M1
L003 1001 M1
L003 1003 M1
L003 1004 M2
L004 1002 M2
L004 1004 M2
L005 1003 M2
L005 1004 M3
I want to separate the data according to the 1st column and the 3rd column.
If the 1st column(leaderCD) and the 3rd column(message) have the same data, merge the 2nd column together,use semicolon,just like this:
leaderCD EmpALL message
L001 1001;1002 M1
L002 1001;1003;1004 M1
L002 1002 M2
L003 1001;1003 M1
L003 1004 M2
L004 1002;1004 M2
L005 1003 M2
L005 1004 M3
I tried group by,but I find group by can't do this.
What should I do?