2011-02-07 60 views
-2

我在数据库中的记录:有没有在SQL中concactenantion的代码?

Column1   Column2 

    1    a 
    1    b 
    1    c 

,其结果将是:

Column1   Result 

    1    abc 

我只是希望这个查询,以便如果我不会用循环:)

+0

您使用哪种DBMS? – bluish 2011-02-07 12:49:51

+1

它似乎你使用SQLServer。所以它是http://stackoverflow.com/questions/4894095/sql-group-by-with-concat和http://stackoverflow.com/questions/941103/concat-groups-in-sql-server – bluish 2011-02-07 12:53:18

回答

1

对于MS SQL,你可以使用:

Declare @result varchar(1000) 
Set @Result = '' 

Select 
     @result = (@result + Column2) 

From MyTable 
Where Column1 = 1 


Select @Result 
-4

使用MySQL或Oracle,您可以使用:

SELECT CONCAT(col1,col2)FROM YOU RTABLE

0

标准SQL的设计没有CONCATENATE设置功能,因为所有的SQL数据类型是标量。