Teradata SQL - 如果条件A1则评估条件b1 ...对于A1,A2,A3

时间:2018-02-23 01:58:37

标签: sql conditional-statements where teradata

enter image description here

这应该产生 -

au  123  john
ph  456  pipin
nz  765  myers
nz  876  philip

2 个答案:

答案 0 :(得分:1)

我认为您只需稍微更改WHERE子句中的语法:

SELECT
    country,
    account_num,
    name
FROM table
WHERE
    country = 'au' AND account_num <> '999' OR
    country = 'ph' AND account_num <> '888' OR
    country = 'br' AND account_num <> '555';

答案 1 :(得分:1)

添加了另一个条件来捕捉除了&#39;以及&#39; ph&#39;以外的其他国家/地区。或者&#39; br&#39;:

SELECT
    country,
    account_num,
    name
FROM table
WHERE
   (country = 'au' AND account_num <> '999') OR
   (country = 'ph' AND account_num <> '888') OR
   (country = 'br' AND account_num <> '555') OR
   country not in ('au', 'ph', 'br');