我对蜂巢很陌生。使用我的case语句,我试图创建一个名为period的变量,该变量在一个时间段内为零,在另一个时间段内为一个,但我得到了一个“无法识别输入”的错误。如何在配置单元中命名case表达式的结果?它会将自己命名为_c7或类似的名称,但是我在下一步使用这个_c7变量时会遇到问题(eof error)。
CREATE TABLE abc.temp2 AS
SELECT a.*,
case
when to_date(date)>='2016-07-01' and to_date(date)<'2017-07-01' then 0
when to_date(date)>='2017-07-01' and to_date(date)<'2018-07-01' then 1
else null
end **as period,**
array_contains(z,'abc') as abc,
array_contains(z,'def') as def
FROM abc.temp a;发布于 2020-07-10 02:33:42
只需将case语句放在一组括号中即可。
CREATE TABLE abc.temp2 AS
SELECT a.*,
(case
when to_date(date)>='2016-07-01' and to_date(date)<'2017-07-01' then 0
when to_date(date)>='2017-07-01' and to_date(date)<'2018-07-01' then 1
else null
end) as period,
array_contains(z,'abc') as abc,
array_contains(z,'def') as def
FROM abc.temp a;https://stackoverflow.com/questions/62765235
复制相似问题