1、判斷某個逗號隔開的字段中有某個值mysql
FIND_IN_SET('a','a,b,c,d') 用 CHARINDEX(','+'b'+',' , ','+'a,b,c'+',') > 0 替代sql
2、模仿mysql的group_concat的示例ide
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