A表
id title
1 123
2 2
3 12
4 3
5 13
需要显示这样的
id 品牌1 品牌2 品牌3
1 有 有 有
2 null 有 null
3 有 有 null
4 null null 有
5 有 null 有
title里面都是单个数的 最大为3 如: id title
1 123
可以把title看成是 1 2 3 然后拿这些数 与品牌去对比
比如第一条数据 拆开之后是 1 2 3 针对品牌1 品牌2 品牌3
而第2条数据 只有2 那就只针对品牌2了
第3条数据 有1 2 那就针对品牌1 和品牌2了
,品牌1=(case when charindex('1',ltrim(title))>0 then '有' else NULL end)
,品牌2=(case when charindex('2',ltrim(title))>0 then '有' else NULL end)
,品牌3=(case when charindex('3',ltrim(title))>0 then '有' else NULL end)
from A