2013-08-01 22 views
0

我有一个表,如下所示如何选择只有一个字段,其中ID号是相同的SQL

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中执行此操作?

+1

您使用哪种DBMS的? MySql-SlqServer-SQLite-Oracle .... –

+1

对不起,其SQL服务器2005 – Win

回答

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 
+0

正是我以后,非常感谢你! – Win

相关问题