0

为了旋转我的大查询表,我找到了这段代码

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函数,它也会返回上面代码的字符串。我在那个功能中错过了什么?

谢谢你的帮助

4

1 回答 1

2

下面使用

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
)  
);
于 2021-04-15T23:14:09.777 回答