在数据库里我如何取出刚查询出的字段下的值,并作判断,如何值中没有“优良中差次”中的任何一个字,我就用union创建一个不存在的值设置为0

解决方案 »

  1.   

    字段中如果不包含优、良、中、差、次中任何一个字,就创建一个类型为不包含的字的行,
    例如,如果字段中没有良,就union 
                                  select '良','0'
    这样!谢谢!
      

  2.   

    select *
    into #tab 
    from 表名
    where 列名 not like '%优%' insert into #tab
    select *
    from 表名
    where 列名 not like '%良%' 
    union all
    select *
    from 表名
    where 列名 not like '%中%' 
    union all
    select *
    from 表名
    where 列名 not like '%差%'
    union all
    select *
    from 表名
    where 列名 not like '%次%' 
    update #tab
    set 列名 = 0
      

  3.   

    我认为LZ的意思是这样id   name 
    1    良中差id   name 
    1    0 良中差
      

  4.   

    sunyj20081() 写的很符合我的意思,但是要把不存在的字段显示出来啊,不是只显示'0',如果没有良,也要把良显示出来啊!