带有if的字符串数组



从与FROM创建的数组字符串,我想包括一个IF条件,但bigquery告诉我,这是不可能的。我有以下错误Syntax error: Expected ")" but got keyword FROM每当我试图做这样的事情:

SELECT 
IF(TRUE, STRING_AGG(x, ' | ')
FROM UNNEST([
IF(FALSE, 'new_customer', NULL), 
IF(TRUE, 'new_customer_vertical', NULL),
IF(TRUE, 'new_customer_expedition', NULL),
IF(FALSE, 'new_customer_pandapro', NULL)
]) AS x, NULL)

如果移除IF条件,则传递

SELECT 
STRING_AGG(x, ' | ')
FROM UNNEST([
IF(FALSE, 'new_customer', NULL), 
IF(TRUE, 'new_customer_vertical', NULL),
IF(TRUE, 'new_customer_expedition', NULL),
IF(FALSE, 'new_customer_pandapro', NULL)
]) AS x

不确定下面是你想做的,但你看起来想要一个标量子查询在IF()函数。

SELECT IF(TRUE, -- some condition
(SELECT STRING_AGG(x, ' | ')
FROM UNNEST([
IF(FALSE, 'new_customer', NULL), 
IF(TRUE, 'new_customer_vertical', NULL),
IF(TRUE, 'new_customer_expedition', NULL),
IF(FALSE, 'new_customer_pandapro', NULL)
]) AS x
), -- IF true
NULL) -- IF false

相关内容

  • 没有找到相关文章

最新更新