使用多行数据透视 BigQuery table
Pivot BigQuery table using multiple rows
为了调整我的大查询 table,我找到了这段代码
SELECT 'SELECT id, ' ||
STRING_AGG(
'MAX(IF(key = "' || key || '", value, NULL)) as `' || key || '`'
)
|| ' FROM `project.dataset.table` GROUP BY id ORDER BY id'
FROM (
SELECT key
FROM `project.dataset.table`
GROUP BY key
ORDER BY key
但即使我应用EXECUTE IMMEDIATE
函数,它也是returns上面代码的字符串。
我在该功能中错过了什么?
感谢您的帮助
下面使用
EXECUTE IMMEDIATE(
SELECT 'SELECT id, ' ||
STRING_AGG(
'MAX(IF(key = "' || key || '", value, NULL)) as `' || key || '`'
)
|| ' FROM `project.dataset.table` GROUP BY id ORDER BY id'
FROM (
SELECT key
FROM `project.dataset.table`
GROUP BY key
ORDER BY key
)
);
为了调整我的大查询 table,我找到了这段代码
SELECT 'SELECT id, ' ||
STRING_AGG(
'MAX(IF(key = "' || key || '", value, NULL)) as `' || key || '`'
)
|| ' FROM `project.dataset.table` GROUP BY id ORDER BY id'
FROM (
SELECT key
FROM `project.dataset.table`
GROUP BY key
ORDER BY key
但即使我应用EXECUTE IMMEDIATE
函数,它也是returns上面代码的字符串。
我在该功能中错过了什么?
感谢您的帮助
下面使用
EXECUTE IMMEDIATE(
SELECT 'SELECT id, ' ||
STRING_AGG(
'MAX(IF(key = "' || key || '", value, NULL)) as `' || key || '`'
)
|| ' FROM `project.dataset.table` GROUP BY id ORDER BY id'
FROM (
SELECT key
FROM `project.dataset.table`
GROUP BY key
ORDER BY key
)
);