所以我有这个代码它工作正常
SELECT NAME,
Country,
NORMAL_STATE,
CURRENT_STATE
FROM SOMS_TABLE
WHERE SOMS_TABLE.NAME LIKE 'AR%' AND
NORMAL_STATE <> CURRENT_STATE
ORDER BY SOMS_TABLE.Country ASC
输出为
但我希望将1和0更改为OPEN&amp;已结束
谢谢你
答案 0 :(得分:3)
select name,
Country,
case NORMAL_STATE
when 1 then 'OPEN'
when 0 then 'CLOSED'
else 'UNKNOWN'
end as NORMAL_STATE,
case CURRENT_STATE
when 1 then 'OPEN'
when 0 then 'CLOSED'
else 'UNKNOWN'
end as CURRENT_STATE
from SOMS_TABLE
where name like 'AR%'
and NORMAL_STATE <> CURRENT_STATE
order by Country
答案 1 :(得分:1)
使用此
CASE NORMAL_STATE
WHEN 1 THEN 'OPEN'
WHEN 2 THEN 'CLOSED'
END AS NORMAL_STATE
同样适用于CURRENT_STATE
答案 2 :(得分:0)
您可以使用IF语句
SELECT NAME, Country,
IF(NORMAL_STATE > 0,'OPEN','CLOSED'),
IF(CURRENT_STATE > 0,'OPEN','CLOSED')
FROM SOMS_TABLE
WHERE SOMS_TABLE.NAME LIKE 'AR%' AND
NORMAL_STATE <> CURRENT_STATE
ORDER BY SOMS_TABLE.Country ASC