如何在 SQL Server 中使行数据以逗号分隔?
CREATE TABLE CountryState
(Country Varchar(15), State Varchar(15))
GO
INSERT INTO CountryState VALUES('India','MH')
INSERT INTO CountryState VALUES('India','DL')
INSERT INTO CountryState VALUES('US','NJ')
INSERT INTO CountryState VALUES('US','NY')
GO
SELECT * FROM CountryState
输出:
Country State
----------------------------
India MH
India DL
US NJ
US NY
我需要以下格式的输出。
Country State
------------------
India MH,DL
US NJ,NY