0

所以我有这个代码它工作正常

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 & CLOSED

在此处输入图像描述
谢谢

4

3 回答 3

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 
于 2012-07-03T18:31:21.277 回答
1

用这个

CASE NORMAL_STATE
    WHEN 1 THEN 'OPEN'
    WHEN 2 THEN 'CLOSED'
END AS NORMAL_STATE

同样对于CURRENT_STATE

于 2012-07-03T18:35:47.380 回答
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
于 2012-07-03T18:33:43.530 回答