#standardsql Bigquery 中的会话数

Number of sessions in #standardsql Bigquery

我希望将此 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

现在是 3 月 14 日,所以日期条件很好。

我猜这是因为重复字段显示的会话数过高。请问有人可以帮忙解决语法问题吗?

Unnest 是不必要的。这将按预期工作:

#standardsql
SELECT 
count(distinct fullvisitorid)

,SUM(totals.visits) AS Sessions
FROM `ga-export-1111.0123456789.ga_sessions_2017*`