如何从视图bigquery中选择?

时间:2018-10-22 03:29:53

标签: view google-bigquery

我想从Bigquery视图中检索实时Google Analytics(分析)数据。附件是我当前的查询:

select datetime(timestamp_micros(visitstarttime*1000000),"Asia/Jakarta") as ga_datetime
, device.operatingSystem as ga_os
, trafficSource.source as ga_source
, trafficSource.medium as ga_medium
,COUNT(DISTINCT CONCAT(CAST(fullvisitorid AS string),CAST(visitid AS string))) AS ga_session
from `43864393.ga_realtime_sessions_view_201810*` 
where _TABLE_SUFFIX between '01' and '31'
group by 1
, 2
, 3 
, 4

我正在使用标准SQL,并且Bigquery返回了

  

无法通过前缀查询视图

更新:

我的bigquery中有以下视图:

  • ga_realtime_sessions_view_20181017
  • ga_realtime_sessions_view_20181018
  • ga_realtime_sessions_view_20181019
  • 一直计数到ga_realtime_sessions_view_20181031

我想从所有这些视图中进行选择。 我该如何解决?

1 个答案:

答案 0 :(得分:1)

您不能在视图中使用通配符。如果仍要合并结果,则可能要查看UNION ALL

您可以在标准SQL中使用UNION ALL合并来自多个表/视图的结果。

这是使用UNION ALL的示例查询

WITH subQ1 AS (SELECT column1 FROM view_1),
     subQ2 AS (SELECT column1 FROM view_2)
SELECT * FROM subQ1
UNION ALL
SELECT * FROM subQ2;

请参阅此处的文档

UNION ALL