标签:group_concat find_in_set sqlserver模仿mysql
一、判断某个逗号隔开的字段中有某个值
FIND_IN_SET(‘a‘,‘a,b,c,d‘) 用 CHARINDEX(‘,‘+‘b‘+‘,‘ , ‘,‘+‘a,b,c‘+‘,‘) > 0 替代
二、模仿mysql的group_concat的示例
SELECT id, val=( SELECT [value] +‘,‘ FROM tb AS b WHERE b.id = a.id FOR XML PATH(‘‘) ) FROM tb AS a GROUP BY id
SELECT id, [val]=STUFF( (SELECT ‘,‘+[value] FROM tb AS b WHERE b.id = a.id FOR XML PATH(‘‘)) , 1 , 1 , ‘‘ ) FROM tb AS a GROUP BY id
--删除、创建临时表 drop table #table1; select * into #table1 from ( SELECT myId,‘auto‘ as type )allData --把数据按myId分类链接,然后按链接后数据的长度倒序排序 select * from ( select myId, val=STUFF( (SELECT ‘、‘+type FROM #table1 AS b WHERE b.myId = ta.myId FOR XML PATH(‘‘)) , 1 , 1 , ‘‘ ) from #table1 ta group by myId ) dd order by LEN(val) desc
本文出自 “风之痕_雪虎” 博客,请务必保留此出处http://snowtiger.blog.51cto.com/12931578/1929498
sqlserver模仿mysql函数FIND_IN_SET,group_concat的功能
标签:group_concat find_in_set sqlserver模仿mysql
原文地址:http://snowtiger.blog.51cto.com/12931578/1929498