Generated on the left side of the table statement
The create table TB (
The name nvarchar (50),
Price1 float,
Price2 float
)
Insert into TB
Select '110 * 300, 11.8, 15 union all
Select '110 * 300, 11.8, and union all
Select '110 * 300, 11.8, 20 union all
Select '110 * 300, 11.8, 25 union all
Select '110 * 300, 11.8, 30 union all
Select '110 * 300, 11.8, 35 union all
Select '110 * 70, 3.5, 15 union all
Select '110 * 70, 7, 15 union all
Select '110 * 70, 3.5, and union all
Select '110 * 70, 7, 17 union all
Select '110 * 70, 3.5, 25 union all
Select '110 * 70, 7, 25
CodePudding user response:
SELECT
A.n ame,
STUFF ((SELECT DISTINCT '/' + CAST (p. rice1 AS VARCHAR) FROM TB b WHERE b.n ame=a.n ame FOR XML PATH (' ')), 1, 1, ' ') price1,
STUFF ((SELECT DISTINCT '/' + CAST (c.p rice2 AS VARCHAR) FROM TB c WHERE c.n ame=a.n ame FOR XML PATH (' ')), 1, 1, ' ') price2
The FROM TB a
GROUP BY a.n ame