If statement 带有IF和While的BigQuery脚本
我需要制作一张纸条来搜索一个表中的正则表达式,并粘贴其他表中所有正则表达式的结果。 问题:某些列存在null,这会中断查询。 列1从不为空。 第2列包含一些空值。 第3列包含大量空值 当第2列为空时,第3列也为空 到目前为止我提出的问题。当不为空时,该选项将正常工作If statement 带有IF和While的BigQuery脚本,if-statement,while-loop,google-bigquery,If Statement,While Loop,Google Bigquery,我需要制作一张纸条来搜索一个表中的正则表达式,并粘贴其他表中所有正则表达式的结果。 问题:某些列存在null,这会中断查询。 列1从不为空。 第2列包含一些空值。 第3列包含大量空值 当第2列为空时,第3列也为空 到目前为止我提出的问题。当不为空时,该选项将正常工作 declare I int64; set N1 = (select count(*) from `table_1`); set I = 1; while I <= N1 do
declare I int64;
set N1 = (select count(*) from `table_1`);
set I = 1;
while I <= N1 do
INSERT `table_2` (eventAction, eventCateroy, eventLabel, Rotulo, Produto)
select
distinct(h.eventInfo.eventAction) as eventAction,
h.eventInfo.eventCategory,
h.eventInfo.eventLabel,
(case
when I=I then (select Rotulo from `table_1` where Cod=I)
end) as Rotulo,
(case
when I=I then (select Produto from `table_1` where Cod=I)
end) as Produto
from `table_3` t, UNNEST(hits) as h
where REGEXP_CONTAINS(h.eventInfo.eventAction, (Select eventAction from `table_1` where Cod=i))
and h.eventInfo.eventCategory = (Select eventCategory from `table_1` where Cod=i);
and REGEXP_CONTAINS(h.eventInfo.eventLabel, (Select eventLabel from `table_1` where Cod=i))
Set I=I+1;
end while;
我需要什么
declare N1 int64;
declare I int64;
set N1 = (select count(*) from `table_1`);
set I = 1;
while I <= N1 do
If eventLabel from table_1 = null
(Insert Query Without eventLabel column)
if eventAction from table_1 = null
(insert query withou eventLabel and eventAction)
else
(query with all columns)
Set I=I+1;
end while;
我没有找到如何编写此代码。如果没有输入数据和预期输出的示例,很难回答此问题,但您应该能够使用SQL解决此问题,如果这有帮助,请告诉我:
WITH A as (
SELECT
eventAction,
eventCategory,
eventLabel,
ROW_NUMBER() OVER() as Iterator,
FROM `table_1`
),
B AS (
SELECT *,
ARRAY(SELECT AS STRUCT * FROM `table_3` t, UNNEST(hits) as h
where REGEXP_CONTAINS(h.eventInfo.eventAction, A.eventAction)
and h.eventInfo.eventCategory = A.eventCategory
and REGEXP_CONTAINS(h.eventInfo.eventLabel, A.event_Label)) as table_3_column,
FROM A)
SELECT *,
CASE
WHEN IFNULL(some_column) then Rotulo
WHEN IFNULL(some_othercolumn) THEN Produto
END AS something_else
FROM B, unnest (table_3_column)
如果没有输入数据和预期输出的示例,很难回答此问题,但您应该能够使用SQL解决此问题,请告诉我这是否有帮助:
WITH A as (
SELECT
eventAction,
eventCategory,
eventLabel,
ROW_NUMBER() OVER() as Iterator,
FROM `table_1`
),
B AS (
SELECT *,
ARRAY(SELECT AS STRUCT * FROM `table_3` t, UNNEST(hits) as h
where REGEXP_CONTAINS(h.eventInfo.eventAction, A.eventAction)
and h.eventInfo.eventCategory = A.eventCategory
and REGEXP_CONTAINS(h.eventInfo.eventLabel, A.event_Label)) as table_3_column,
FROM A)
SELECT *,
CASE
WHEN IFNULL(some_column) then Rotulo
WHEN IFNULL(some_othercolumn) THEN Produto
END AS something_else
FROM B, unnest (table_3_column)
我不认为在这里使用循环是正确的方法,更不用说这种执行的$ost了,而且看起来它可以用简单的基于集合的方式来完成——这意味着只需一个查询。我建议您用输入数据示例和预期输出以及要应用的逻辑来展示您的用例:oI不认为在这里使用循环是正确的方法,更不用说这种执行的$ost了,看起来它可以用简单的基于集合的方式来完成——这意味着只需一个查询。我建议您用输入数据示例和预期输出以及要应用的逻辑来展示您的用例:o