我现在有一条sql语句
select *
from att_unattinfo where att_udate>='2009-01-01'
and att_udate<'2009-02-01' and (att_amtype='曠工'
or att_pmtype='曠工')=============================
查询到的结果是:
att_udate   att_uname   att_amtype   att_pmtype
 2009-1-6    steven       曠工         請假
 2009-1-3    steven       曠工         曠工
 2009-1-2    apple        非帶薪假     曠工
我现在想在这个基础上。把原来的sql改写
加个判断  如果查询的数据中att_amptype 与att_pmtype 里含有非旷工的内容
则为空。我想让它的结果如下:
================
att_udate   att_uname   att_amtype   att_pmtype
 2009-1-6    steven       曠工         
 2009-1-3    steven       曠工         曠工
 2009-1-2    apple                    曠工
救急。

解决方案 »

  1.   

    select att_udate,  att_uname,
      case att_amtype when '曠工' then att_amtype else '' end  att_amtype,
      case att_pmtype when '曠工' then att_pmtype else '' end  att_pmtype,
    from att_unattinfo where att_udate>='2009-01-01'
    and att_udate <'2009-02-01' and (att_amtype='曠工'
    or att_pmtype='曠工')
      

  2.   

    更正
    select att_udate, att_uname, 
    case att_amtype when '曠工' then att_amtype else '' end att_amtype, 
    case att_pmtype when '曠工' then att_pmtype else '' end att_pmtype 
    from att_unattinfo 
    where att_udate>='2009-01-01' 
    and att_udate <'2009-02-01' 
    and (att_amtype='曠工' or att_pmtype='曠工')
      

  3.   


    select att_udate,att_uname,case when att_amtype<>'曠工' then '',case when att_pmtype<>'曠工' then '' from (select * 
    from att_unattinfo where att_udate>='2009-01-01' 
    and att_udate <'2009-02-01' and (att_amtype='曠工' 
    or att_pmtype='曠工') )你试一下...