SQL SERVER grouping group by after , Merge strings together , Comma separated .

Original data :

effect :

code :
-use DB01; -- Build table create table dbo.tb_user_product( id int null ,name
varchar(10) null ,product varchar(100) null ,amount decimal(9,2) null ); --
insert data insert into dbo.tb_user_product values ('1001',' Universiade ',' millet 10 Supreme Commemorative Edition ',5999);
insert into dbo.tb_user_product values ('1001',' Universiade ',' rice 10 Delicious version ',6800); insert
into dbo.tb_user_product values ('1001',' Universiade ',' Huawei 30max',8999); insert into
dbo.tb_user_product values ('1001',' Little star ',' Huawei 10Pro',3500); insert into
dbo.tb_user_product values ('1001',' Little star ','OPPO9',2200); insert into
dbo.tb_user_product values ('1001',' A Fei ',' Samsung Note20',8500); -- query select * from
dbo.tb_user_product; -- group by Strings are separated by commas and merged together select id ,name ,sum(amount) as
amount ,products = STUFF( (select ','+product from dbo.tb_user_product b where
a.id = b.id and a.name = b.name for xml path('')) ,1 ,1 ,'') from
dbo.tb_user_product a group by id ,name;
 

Technology
©2019-2020 Toolsou All rights reserved,
java Comparing attribute values between two objects utilize Python handle Excel data ——xlrd,xlwt library Bidirectional linked list Why? Python Not a future oriented programming language ?Python【 Assignment statement 】 Special lecture , You can't just a=b ah ! Suggest mastering ! utilize Python handle Excel data ——pandas library see SQL-SERVER Data volume and occupied space of database and each table PID The algorithm finally figured out the principle , It was so simple web Two front-end practical games ( Attached source code ) Beginners learn Python Be sure to know what his basic algorithms are ? What is the function ?