我正在使用Oracle SQL并且正在尝试构建满足以下条件的sql: 如果PS_EMPLOYEES.COUNTRY<> USA,请输入PS_EMPLOYEES.POSTAL,否则请留空
以下代码执行此操作除外,它会检查该国家是否与美国相同。我该怎么做?
, ZIPCODE =
(SELECT decode(t2.COUNTRY, 'USA', t2.POSTAL, ' ') zipcode
FROM PS_EMPLOYEES t2
...
答案 0 :(得分:3)
嗯,你可以使用一个case语句(不是特定于oracle):
, ZIPCODE =
(SELECT CASE WHEN t2.COUNTRY != 'USA' THEN t2.POSTAL ELSE ' ' END) zipcode
FROM PS_EMPLOYEES t2
...
或者你可以不同地使用解码:
, ZIPCODE =
(SELECT decode(t2.COUNTRY, 'USA', ' ', t2.POSTAL) zipcode
FROM PS_EMPLOYEES t2
...
答案 1 :(得分:2)
您可以使用案例陈述......如下所示
(select (case when t2.country != 'USA' then t2.postal
else ' '
end ) zipcode from PS_EMPLOYEES t2
....