表1:字段1
A
A
B
A
B
B
B求一SQL语句可以实现:表2
字段1(A)    字段2(B)
1              0
1              0
0              1
0              1
0              1

解决方案 »

  1.   

    用select ..case.... when试试看
      

  2.   

    select
        case 字段1 when 'A' then 1 else 0 end as [字段1(A)],
        case 字段1 when 'B' then 1 else 0 end as [字段1(B)]
    into 表2 from 表1
      

  3.   

    select  * from (case 表1.字段1 when a then "1" else "0") as 字段1(A), (case 表1.字段1 when b then "0" else "1") as 字段1(b)) a
      

  4.   

    select
        case 字段1 when 'A' then 1 else 0 end as [字段1(A)],
        case 字段1 when 'B' then 1 else 0 end as [字段1(B)]
    into 表2 from 表1这个结果就非常准确