使用场景:把某一列值转换为逗号分隔的字符串 例子:比如查询所有的的表空间如下,现在要获得所有的表空间用逗号分隔的字符串(比如rman duplicate的时候skip表空间) SQL> select name from v$tablespace; NAME ------------------------------ SYSTEM SYSAUX CTXD APPS_TS_TX_DATA APPS_TS_TX_IDX OWAPUB APPS_TS_QUEUES ODM OLAP APPS_TS_T…
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…
原始数据,需要拼接成一行 select * from (select d.*,(SELECT count ([Keyword])FROM [DragonGuoShi].[dbo].[ArticleInfo]where Keyword like'%'+d.Keyword+'%' and [ArticleCreateDate]>'2018-06-10') as Num from (select distinct(Keyword) from( select SUBSTRING( Keyword,num…