SQL条件判断语句

 第一种:

SELECT
 CASE
 WHEN price IS NULL THEN ‘Not yet priced’
 WHEN price < 10 THEN ‘Very Reasonable Title’
 WHEN price >= 10 and price < 20 THEN ‘Coffee Table Title’
 ELSE ‘Expensive book!’
 END AS “Price Category”,
CONVERT(varchar(20), title) AS “Shortened Title”
FROM pubs.dbo.titles
ORDER BY price

 第二种:

SELECT au_fname, au_lname,
   CASE state
      WHEN ‘CA’ THEN ‘California’
      WHEN ‘KS’ THEN ‘Kansas’
      WHEN ‘TN’ THEN ‘Tennessee’
      WHEN ‘OR’ THEN ‘Oregon’
      WHEN ‘MI’ THEN ‘Michigan’
      WHEN ‘IN’ THEN ‘Indiana’
      WHEN ‘MD’ THEN ‘Maryland’
      WHEN ‘UT’ THEN ‘Utah’
        END AS StateName
FROM pubs.dbo.authors
ORDER BY au_lname 

    原文作者:SQL
    原文地址: https://blog.csdn.net/hbzhangjian/article/details/1003684
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞