select ID, Name = ( stuff ( ( select ',' + Name from Table_1 where ID = a.ID for xml path('') ),1,1,'' ) ) from Table_1 a group by ID 原始数据: ID Name A S A M A L B S B M B L 结果数据: ID NameA S,M,LB S,M,L…
select '['+title_a+','+title_b +']' from A for xml path('') SELECT *, (select '['+title_a+','+title_b +']' from A where A.t_id=B.t_id for xml path('')) FROM B…
如下表: 表名:Test ID RowID Col1 Col2 1 1 A A 2 1 B A 3 1 A B 4 1 C B 1,查找表中字段重复的只查找一次 select distinct Col1 from Test ; select Col1 from Test where ID in(select min(ID) from Test group by Col1 ); 结果为: A B C 2,统计并查询该字段出现的数量 SELECT Col1,COUNT(Col1) FROM Tes…
Oracle一列的多行数据拼成一行显示字符 oracle 提供了两个函数WMSYS.WM_CONCAT 和 ListAgg函数. www.2cto.com 先介绍:WMSYS.WM_CONCAT 例: id name 1 aa 2 bb 3 cc 要的结果是"aa,bb,cc" select WMSYS.WM_CONCAT(a.name) from user a 这样的话,查询出的结果:…
项目中要将查询出的一列的多行内容拼接成一行,如下图:ypmc列. ms sql server: 网上查到相关资料如下:http://blog.csdn.net/rolamao/article/details/7745972 写的还不错. 我写的如下(存储过程中): select (STUFF((select '';''+ywmc from JB_TNB_HZ_YYQK where XT_JLZT =''0'' and SFLSH=a.lsh for xml path('''')),1,1,'''…