範例1.
SELECT
CASE 1
WHEN 1 THEN 'one'
WHEN 2 THEN 'two'
ELSE 'more'
END
範例2.
SELECT
CASE cid
WHEN 'kr' THEN 'Korea'
WHEN 'jp' THEN 'Japan'
ELSE 'Taiwan'
END AS country
FROM customer
說明:假設客戶資料表只有國家簡碼(cid, eg. jp...),但需求 select 出來時要顯示國家全名。
No comments:
Post a Comment