初始数据:
假设表名为test
select distinct(b.creatDate),stuff((select ',' + a.name from test a where a.type = '新增' and b.creatDate >= a.creatDate and not exists(select 1 from test c where c.creatDate <= b.creatDate and c.creatDate >= a.creatDate and c.type = '删除' and c.name = a.name) for xml path('')),1,1,'') as addData from test b
```sql
SELECT T1.ID,
STUFF((SELECT ',' + T2.Name
FROM Table T2
WHERE T2.CreateDate <= T1.CreateDate
AND T2.Type = '新增'
FOR XML PATH('')), 1, 1, '') AS 新增列 ,
T1.CreateDate
FROM Table T1
WHERE T1.Type = '新增'
OR T1.Type = '删除'
ORDER BY T1.CreateDate ASC;
```