0

我有一张如下表

bugID  | name  | description  | comment
----------------------------------------------------------------
1      | bug1  | first bug    | <p></p>
1      | bug1  | first bug    | <p>this is the first bug</p>
1      | bug1  | first bug    | <p>this needs fixing</p>
2      | bug2  | second bug   | <p>this is the second bug</p>
3      | bug3  | third bug    | <p>bug number 3</p>

如果我从该表中选择 *,我想按如下方式取回记录

1, bug1, first bug, <p></p>, <p>this is the first bug</p>, <p>this needs fixing</p>
2, bug2, second bug, <p>this is the second bug</p>
3, bug3, third bug, <p>bug number 3</p>

有没有办法在 SQL 中做到这一点?

4

1 回答 1

1

假设这是 SQL Server

SELECT bugID,
       name,
       description,
       STUFF(( SELECT ',' + comment 
                  FROM Table1 I Where I.bugID= O.bugID
                FOR
                  XML PATH('')
                ), 1, 1, '')
FROM   Table1 O
GROUP BY bugID,
       name,
       description
于 2013-08-01T08:21:33.823 回答