表结构如下
AA   BB
03   10
03   20
04   30
04   15
03   25我想查询把AA=03的显示成:人事,AA=04的显示成:财务
得到结果如下
AA     BB
人事   10
人事   20
财务   30
财务   15
人事   25

解决方案 »

  1.   


    select case aa when 03 then '人事' when 04 then '财务' else '' end as aa ,bb from tb
      

  2.   


    select (case when aa = '03' then '人事' when aa = '04' then '财务' else '' end) as aa ,bb 
    from tb
      

  3.   

    select AA=(case AA when '03' then '人事' when '04' then '财务' end),BB from tb
      

  4.   

    Create table tb (aa varchar(10),bb varchar(10))
    Go
    insert into tb
    select '03' ,'10' union all
    select '03', '20' union all
    select '04' ,'30' union all
    select '04', '15' union all
    select '03', '25'select case aa when '03' then '人事' when '04' then '财务' end as a,bb
    from tba    bb
    ---- ----------
    人事   10
    人事   20
    财务   30
    财务   15
    人事   25(5 行受影响)
      

  5.   


      select case AA when '03' then '人事' when '04' then '财务' else '其他' end as AA,BB from TB