我知道在MySQL中有GROUP_CONCAT,在Sybase中我认为它是LIST,如另一个答案中所述:
SELECT id, LIST(data||', ') FROM yourtable GROUP BY id
在MsSQL中你可以使用一个函数(不知道在SyBase中是否有类似的somenthing)
CREATE FUNCTION [dbo].[GetDataForID] ( @ID int ) RETURNS varchar(max) AS BEGIN declare @output varchar(max) select @output = COALESCE(@output + ', ', '') + data from table where ID = @ID return @output END GO
然后:
SELECT ID, dbo.GetDataForID(ID) as Data FROM Table GROUP BY ID