我正试图在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,
我如何让它工作? 如果所有约会类型和约会目的都是空的,那么discuss_other也应该是空的,即0 - 否则discuss_other应该是1
答案 0 :(得分:0)
试试这个:
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
答案 1 :(得分:0)
在SQL中,"空"通常意味着*
。所以,我想知道你是否真的打算使用其中一个结构:
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
最后,同一个表中像数组一样的多个列通常是一个不好的标志。通常,这表明您需要联结表。