哪个哥哥有无脑一点的文档啊,我想看看,我在各种帮助和网站上都得不到正确的意思
看的迷迷糊糊的,谢谢啊,给我文档或者传送门都可以,

解决方案 »

  1.   


    --两种用法
    select case when 字段1 = 值1 then 值1+10 else 值1-10 end
           case 字段1 when 值1 then 值1+10 else 值1-10 end
    from your_table
      

  2.   


    --上面好了一个逗号
    --两种用法
    select case when 字段1 = 值1 then 值1+10 else 值1-10 end
           ,case 字段1 when 值1 then 值1+10 else 值1-10 end
    from your_table--when可以有多个
    --两种用法
    select case when 字段1 = 值1 then 字段1 + 10 
                when 字段1 = 值2 then 字段1 + 20
                when 字段1 = 值3 then 字段1 + 30
                else 字段1 - 10 
           end,
           case 字段1 when 值1 then 字段1 + 10
                      when 值2 then 字段1 + 20
                      when 值3 then 字段1 + 30
                      else 字段1 - 10
           end
    from your_table
      

  3.   

    主要是现在我不知道什么时候需要用case,也不知道case能实现什么。
    或者说实现一个功能,用case是最简单的。不知道什么时候用
      

  4.   


    想想C语言里面的case就知道了,意思是一样的
    比如表里有个字段:状态,而状态只会有三种:1/2/3,分别代表'默认值','成功','失败'
    现在要统计这三种状态在表中各自的总数,就要用到case了
    select case 状态 when 1 then '默认值'
                    when 2 then '成功'
                    when 3 then '失败'
           end
           ,count(1)
    from your_table
    group by 状态
    /*
    --结果
    状态|总数
    默认值|100
    成功|90
    失败|80*/