我的表格中有一列(SERVICE_ID
),我只能有3个值:0,1和2.
在SELECT
上,我想将这些值更改为英文单词以供显示:
select client, SERVICE_ID
from customers
目前显示:
| John | 1
| Mike | 0
| Jordan | 1
| Oren | 2
我想将查询更改为:
| John | QA
| Mike | development
| Jordan | QA
| Oren | management
有没有办法只使用select?
答案 0 :(得分:9)
SELECT client,
CASE SERVICE_ID
WHEN 0 THEN 'development'
WHEN 1 THEN 'QA'
WHEN 2 THEN 'management'
END AS SERVICE
FROM customers
虽然我为Services
添加了一个包含SERVICE_ID, Name
列的单独表格,然后加入其中以检索服务名称。
答案 1 :(得分:0)
CREATE TABLE `serviceID_lookup` (
`serviceID` INT(10) NULL,
`Description` VARCHAR(50) NULL
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;
select c.client, sl.Description
from customers c
inner join serviceID_lookup sl on sl.serviceID = c.SERVICE_ID