SQL SERVER CASE WHEN用法

相当于switch…case…
可在分组时模糊分组

SELECT 
  CASE 
    WHEN FRUIT = 'A' THEN 'APPLE' 
    WHEN FRUIT = 'B' THEN 'BANANA'     
    ELSE  FRUIT
  END AS FRUIT
FROM FRUIT_TABLE;

As a reminder remember; no assignment is performed the value becomes the column contents. (If you wanted to assign that to a variable you would put it before the CASE statement).

This could also be written with CASE FRUIT WHEN ‘A’…

猜你喜欢

转载自blog.csdn.net/u010178308/article/details/88352373