这种方法将解决此问题:
DECLARE @Example TABLE (Id int, Item varchar(20))INSERT INTO @Example (ID, Item)SELECt 1, 'TextLineA' UNIOn ALLSELECT 1, 'TextLineB' UNIOn ALLSELECT 2, 'TextLineA' UNIOn ALLSELECT 3, 'TextLineA' UNIOn ALLSELECT 3, 'TextLineB' UNIOn ALLSELECT 3, 'TextLineC'select ID, MAX(CASE WHEN Item='TextLineA' THEN 1 ELSE 0 END) as TextLineA, MAX(CASE WHEN Item='TextLineB' THEN 1 ELSE 0 END) as TextLineB, MAX(CASE WHEN Item='TextLineC' THEN 1 ELSE 0 END) as TextLineCFROM @ExampleGROUP BY ID
结果是:
ID TextLineA TextLineB TextLineC1 1102 1003 111
其中1为true,0为false。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)