表test1  只有字段core
core 
1
10 
40
59
60
79
90
100
大于等于60分的pass,小于60分fail,写SQL语句输出一些信息:
core  
1     fail
10    fail
40    fail
59    fail
60    pass
79    pass
90    pass
100   pass

解决方案 »

  1.   


      select core, (case where core<60 then 'fail' when core>=60 and core<=100 
                    then 'pass' end) 
      from test1
      

  2.   

    不好意思,笔误,把where改成when
      

  3.   

    select core,decode(sign(core-60),1,'pass',0,'pass',-1,'fail) 
    from tbselect core,case when core>=60 then 'pass' else 'fail' end 
    from tb
      

  4.   


    --修正下
    select core,decode(sign(core-60),1,'pass',0,'pass',-1,'fail') 
    from tbselect core,case when core>=60 then 'pass' else 'fail' end 
    from tb
      

  5.   

    因为大等60都算通过, 也可以
    select core,decode(sign(core-60),-1,'fail','pass') 
    from tb
      

  6.   

    select core,decode(sign(core-60),-1,'fail','pass') 
    from tb
      

  7.   

    select core,
           case when core>=60 then 'pass'
                when core<60 then 'fail'
                end as 
    from test1 
      

  8.   

    select core, decode(sign(core-60), -1, 'fial', 'pass')  from test1;
      

  9.   

    decode 和case when .. then都一样,楼主看看语法就懂了
      

  10.   

    select t.core ,case when t.core>=60 then 'pass' when t.core <60 then 'fail'  from test1 t; 
    简单些啊~哈哈
      

  11.   

    create table S(core int)
    insert into S
    select 1 union all
    select 10 union all
    select 40 union all
    select 59 union all
    select 60 union all
    select 79 union all
    select 90 union all
    select 100select core,(case when core<60 then 'fail' when core>=60 then 'pass' end) as 
    from S