select VAT01,
max(case when ACE01=21 then BCE03 else '' end) as A,
max(case when ACE01=23 then BCE03 else '' end) as B,
max(case when ACE01=22 then BCE03 else '' end) as C
 from t group by VAT01这样试试

解决方案 »

  1.   

    create table T(vax01 int null ,vat01 int null,ace01 int null ,bce03 nchar(10) null)
    insert T
    select 45346,1642103,21,'张燕' union all
    select 45347,1642103,22,'王正'union all
    select 45348,1642103,23,'陈方' union all
    select 45349,1642103,02,'周梅'union all
    select 45350,1642103,01,'李强' union all
    select 45351,1642103,11,'吕布'union all
    select 45352,1642106,11,'刘伟' union all
    select 45353,1642106,22,'王正'union all
    select 45354,1642106,23,'周青'select vat01 ,
    max(case when ace01='21' then bce03 end) as A,
    max(case when ace01='23' then bce03 end) as B,
    max(case when ace01='22' then bce03 end) as C
    from t
    group by vat01 
      

  2.   

    能解释下为什么where BCE03<>'' and len(BCE03)>1 and ISNULL(BCE03,'0')<>'0'都不行
    非要max吗