在BigQuery SQL中支持UNION功能 [英] Support UNION function in BigQuery SQL

查看:101
本文介绍了在BigQuery SQL中支持UNION功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

BigQuery似乎还没有支持UNION:
https:/ /developers.google.com/bigquery/docs/query-reference



(我并不是说将源表合并到一起,它就是这样。 )



是否即将推出?

解决方案

以便您可以合并查询结果,您可以在BigQuery中使用子查询


  SELECT foo,bar 
FROM
(SELECT integer(id)AS foo,string(title)AS bar
FROM publicdata:samples.wikipedia limit 10),
(SELECT integer(year)AS foo,string(状态)AS bar
FROM publicdata:samples.natality limit 10);

这几乎完全等同于SQL

  SELECT id AS foo,title AS bar 
FROM publicdata:samples.wikipedia limit 10
UNION ALL
SELECT year AS foo,state AS bar
FROM publicdata:samples.natality limit 10;

(注意,如果想要SQL UNION而不是UNION ALL,这不起作用)



或者,您可以运行两个查询并追加结果。


BigQuery does not seem to have support for UNION yet: https://developers.google.com/bigquery/docs/query-reference

(I don't mean unioning tables together for the source. It has that.)

Is it coming soon?

解决方案

If you want UNION so that you can combine query results, you can use subselects in BigQuery:

SELECT foo, bar 
FROM
  (SELECT integer(id) AS foo, string(title) AS bar 
   FROM publicdata:samples.wikipedia limit 10),
  (SELECT integer(year) AS foo, string(state) AS bar 
   FROM publicdata:samples.natality limit 10);

This is almost exactly equivalent to the SQL

SELECT id AS foo, title AS bar 
FROM publicdata:samples.wikipedia limit 10
UNION ALL
SELECT year AS foo, state AS bar 
FROM publicdata:samples.natality limit 10;

(note that if want SQL UNION and not UNION ALL this won't work)

Alternately, you could run two queries and append the result.

这篇关于在BigQuery SQL中支持UNION功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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