日期:2014-05-18 浏览次数:20536 次
create table T_UserCount (ID int, D1 varchar(3), D2 varchar(3), D3 varchar(3),D4 varchar(3),D5 varchar(3) ) insert into T_UserCount select 1, '√', '√', 'A', 'B', 'C' union all select 2, '√', 'A', 'B', 'A', 'A' union all select 3, 'A', '√', 'A', 'E', 'F' union all select 4, 'F', 'A', 'G', 'E', 'D' select ID,D1,D2,D3,D4,D5, 5-len(replace(D1+D2+D3+D4+D5,'A','')) 'A', 5-len(replace(D1+D2+D3+D4+D5,'B','')) 'B', 5-len(replace(D1+D2+D3+D4+D5,'C','')) 'C', 5-len(replace(D1+D2+D3+D4+D5,'D','')) 'D', 5-len(replace(D1+D2+D3+D4+D5,'E','')) 'E', 5-len(replace(D1+D2+D3+D4+D5,'F','')) 'F', 5-len(replace(D1+D2+D3+D4+D5,'G','')) 'G' from T_UserCount ID D1 D2 D3 D4 D5 A B C D E F G ----------- ---- ---- ---- ---- ---- ----------- ----------- ----------- ----------- ----------- ----------- ----------- 1 √ √ A B C 1 1 1 0 0 0 0 2 √ A B A A 3 1 0 0 0 0 0 3 A √ A E F 2 0 0 0 1 1 0 4 F A G E D 1 0 0 1 1 1 1 (4 row(s) affected)