0

I have a query which gets all public transport subscriptions. A subscription can have multiple related companies. So I wanted to do with my query is to get all the subscriptions and instead of creating a row each time I have a related company, the companies should by group into one column. Is it possible to do that?

Here's the query :

SELECT pts.Id_PublicTransportSubscription, 
       pts.Amount, 
       ptc.Name
FROM bm_PublicTransportSubscriptions AS pts 
  INNER JOIN bm_PublicTransportSubscriptionByCompany AS ptsbc 
  ON pts.Id_PublicTransportSubscription = ptsbc.Id_PublicTransportSubscription 
  INNER JOIN bm_PublicTransportCompanies AS ptc 
  ON ptsbc.Id_PublicTransportCompany = ptc.Id_PublicTransportCompany

I'm using SQL Server 2008.

4

1 回答 1

0

您可以使用GROUP_CONCAT聚合函数。

于 2013-05-06T08:20:21.127 回答