Case When Then

用法1:

 case [字段]
         when '字段等于相应的value' then 表达式
         when '字段等于相应的value' then 表达式
         else ''
      end 
   
eg:select sort,qty,
    case qty
      when 1 then '少'
      when 2 then '中'
      when 3 then '多'
      else '未知'
    end as [数量范围]
  from test

用法2:

case 
         when [条件] then 表达式
         when [条件] then 表达式
         else ''
      end 
select sort,qty,
    case 
      when qty=1 then '少'
      when qty=2 then '中'
      when qty=3 then '多'
      else '未知'
    end as [数量范围]
    from test 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-04
  • 2023-03-18
  • 2021-08-19
  • 2022-01-21
  • 2021-09-20
猜你喜欢
  • 2021-12-02
  • 2021-10-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-06
  • 2022-12-23
相关资源
相似解决方案