如何在BigQuery中取消转义? [英] How to unpivot in BigQuery?

查看:118
本文介绍了如何在BigQuery中取消转义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在BigQuery中有一个配置如下的表:

但我想要查询配置如下的表:





创建此表的SQL代码的样子是什么?



谢谢! / b>使用表格的UNION(在BigQuery中使用','),加上一些列别名:
$ div class =h2_lin>解决方案

  SELECT位置,大小,数量
FROM(
SELECT位置,'Small'as Size,Small as Small FROM [table]
),(
SELECT Location,'Medium'as Size,Medium as Quantity FROM [table]
),(
SELECT Location,'Large'as Size,Large as Quantity FROM [表格]


Not sure what functions to call, but transpose is the closest thing I can think of.

I have a table in BigQuery that is configured like this:

but I want to query a table that is configured like this:

What does the SQL code look like for creating this table?

Thanks!

解决方案

Use the UNION of tables (with ',' in BigQuery), plus some column aliasing:

SELECT Location, Size, Quantity
FROM (
  SELECT Location, 'Small' as Size, Small as Quantity FROM [table]
), (
  SELECT Location, 'Medium' as Size, Medium as Quantity FROM [table]
), (
  SELECT Location, 'Large' as Size, Large as Quantity FROM [table]
)

这篇关于如何在BigQuery中取消转义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆