Sql 克劳德拉的条件从句

Sql 克劳德拉的条件从句,sql,cloudera-cdh,Sql,Cloudera Cdh,我正试图获得一个在cloudera中工作的if,then子句,大致如下: if (appointment_purpose = '') and appointment_purpose2 = '') and appointment_type2 = '') and appointment_type3 = '') and appointment_type4 = '') and appointment_type5 = '') and discuss_other ' ') then di

我正试图获得一个在cloudera中工作的if,then子句,大致如下:

    if (appointment_purpose = '') and 
appointment_purpose2 = '') and 
appointment_type2 = '') and 
appointment_type3 = '') and 
appointment_type4 = '') and 
appointment_type5 = '') and 
discuss_other ' ') then
discuss_other = 0
else discuss_other = 1,
我怎样才能让它工作? 如果所有约会类型和约会目的均为空,则“讨论其他”也应为空,即0-否则“讨论其他”应为1

SELECT (CASE WHEN appointment_purpose = '' 
AND appointment_purpose2 = ''
AND appointment_type2 = ''
AND appointment_type3 = ''
AND appointment_type4 = ''
AND appointment_type5 = ''
AND discuss_other ' '
THEN 0
ELSE 1
) as discuss_other
FROM tableName
在SQL中,“empty”通常表示
NULL
。所以,我想知道你是否真的想要这些构造之一:

select (case when appointment_purpose is null and
                  appointment_purpose2 is null and
                  appointment_type2 is null and
                  appointment_type3 is null and
                  appointment_type4 is null and
                  appointment_type5 is null and
                  discuss_other is null
             then 0 else 1
        end) as discuss_other
因为其中一个值有一个空格,我想知道您是否要同时处理空格和空值:

select (case when (appointment_purpose is null or replace(appointment_purpose, ' ', '') = '') and
                  (appointment_purpose2 is null or replace(appointment_purpose2, ' ', '') = '') and
                  (appointment_purpose3 is null or replace(appointment_purpose3, ' ', '') = '') and
                  (appointment_purpose4 is null or replace(appointment_purpose4, ' ', '') = '') and
                  (appointment_purpose5 is null or replace(appointment_purpose5, ' ', '') = '') and
                  (discuss_other is null or replace(discuss_other, ' ', '') = '')
             then 0 else 1
        end) as discuss_other

最后,同一个表中的多个列的行为类似于一个数组,这通常是一个坏兆头。通常,这表明您需要一个连接表。

我明白您的意思。Cloudera似乎不喜欢替换:遇到:替换预期:CASE、CAST、DEFAULT、EXISTS、FALSE、IF、INTERVAL、not、NULL、TRUNCATE、TRUE、标识符引起的:异常:语法错误