- 請顯示欄位: 姓名、電話、喜不喜歡此網站
- 使用SELECT CASE 讓欄位更清楚
- 加上別名
請顯示欄位: 姓名、電話、喜不喜歡此網站
select Name,phone,like_web FROM cantact_t
使用SELECT CASE 讓欄位更清楚
select Name,phone, case like_web
when 0 then '喜歡'
when 1 then '不喜歡'
when 2 then '還OK'
END
FROM cantact_t
另一種寫法
select Name, case
when like_web=0 then '喜歡'
when like_web=1 then '不喜歡'
when like_web=2 then '還OK'
END
FROM cantact_t
加上別名
select Name,phone, case like_web
when 0 then '喜歡'
when 1 then '不喜歡'
when 2 then '還OK'
END
AS like_web
FROM cantact_t
select Name, case
when like_web=0 then '喜歡'
when like_web=1 then '不喜歡'
when like_web=2 then '還OK'
END
AS Answer
FROM cantact_t
試著練習把state狀態值改成中文 "寫入、已讀、已回覆、結案
select name, email,
case `state`
when 'IN' then '寫入'
when 'RD' then '已讀'
when 'RY' then '已回覆'
when 'FH' then '結案'
AS state
END
FROM cantact_t
請試著顯示欄位: 姓名、電話、喜不喜歡此網站、狀態 (並把代號變成中文)
select
name, phone,email,
case like_web
when 0 then '喜歡'
when 1 then '不喜歡'
when 2 then '還可以'
END AS 'likeweb',
case state
when 'IN' then '寫入'
when 'RD' then '已讀'
when 'RY' then '已回覆'
when 'FH' then '結案'
END
AS 'state'
FROM cantact_t
Yiru@Studio - 關於我 - 意如