我希望将这个Bigquery #legacySQL查询转换为#standardsql。
#legacySQL
SELECT SUM(totals.visits) AS Sessions,
COUNT(DISTINCT(fullVisitorID), 2000000) as Distinct_Users #this doesn't include null values and I've increased the sample size to 2000000 (Learn more)
FROM TABLE_DATE_RANGE([0123456789.ga_sessions_],TIMESTAMP('2017-01-01'),TIMESTAMP('2017-03-13'))
到目前为止,我的用户数量是正确的,但却难以获得正确的会话数量:
#standardsql
SELECT
count(distinct fullvisitorid)
,SUM(totals.visits) AS Sessions
FROM `ga-export-1111.0123456789.ga_sessions_2017*`
,UNNEST (hits) AS hits
现在是三月十四日,所以日期条件还不错。
我想这是因为重复的字段显示会话数量过多。任何人都可以帮助解决语法问题吗?
答案 0 :(得分:1)
Unnest是不必要的。这将是有意的:
#standardsql
SELECT
count(distinct fullvisitorid)
,SUM(totals.visits) AS Sessions
FROM `ga-export-1111.0123456789.ga_sessions_2017*`