你可以帮我解决这个问题,在标准的SQL for BigQuery中转换这个查询吗?我收到此错误无法访问类型为ARRAY>的值的字段页面at hits.page.hostname LIKE'weite.fr'。请告诉我处理该问题以纠正它。
#standardSQL
SELECT DATE,MAX(CASE
WHEN customDimensions.index = 1 THEN customDimensions.value END) AS CUSTOMDIMENSIONS_VALUE, visitNumber, fullvisitorid, visitStartTime, SEC_TO_TIMESTAMP(visitStartTime) AS humain, TIME (visitStartTime+3600 ) AS Paris_timezone, hits.hour, hits.minute, CONCAT(fullvisitorid, STRING(visitid)) AS sessionid, MAX(CASE
WHEN hits.customDimensions.index = 11 THEN hits.customDimensions.value END) AS localproductname,
device.deviceCategory,
hits.page.pagePath,
IFNULL(hits.page.pagePathLevel2,'') AS HITS_PAGE_PAGEPATHLEVEL2,
IFNULL(hits.page.pagePathLevel3,'') AS HITS_PAGE_PAGEPATHLEVEL3,
MAX(CASE WHEN hits.customDimensions.index = 14 THEN hits.customDimensions.value END) AS assetpurpose,
MAX(CASE WHEN hits.customDimensions.index = 27 THEN hits.customDimensions.value END) AS pathology,
hits.hitNumber
FROM `85801771.ga_sessions*`
CROSS JOIN UNNEST(customDimensions) AS customDimension
CROSS JOIN UNNEST(hits) AS hit
WHERE _TABLE_SUFFIX BETWEEN '20161025' AND '20161026'
AND hits.page.hostname LIKE 'website.fr'
AND customDimensions.value != "null"
AND hits.page.pagePath LIKE 'poiu'
AND hits.type = 'PAGE'
AND (customDimensions.index = 1
OR hits.customDimensions.index = 11
OR hits.customDimensions.index = 14
OR hits.customDimensions.index = 27 )
GROUP BY
DATE,
visitStartTime,
humain,
Paris_timezone,
hits.hour,
hits.minute,
fullVisitorId,
sessionid,
visitNumber,
device.deviceCategory,
hits.page.pagePath,
HITS_PAGE_PAGEPATHLEVEL2,
HITS_PAGE_PAGEPATHLEVEL3,
hits.hitNumber
ORDER BY DATE,
visitStartTime,
device.deviceCategory,
humain,
Paris_timezone,
hits.hour,
hits.minute,
fullVisitorId,
sessionid,
visitNumber,
hits.page.pagePath,
HITS_PAGE_PAGEPATHLEVEL2,
HITS_PAGE_PAGEPATHLEVEL3,
hits.hitNumber DESC
LIMIT 100000
答案 0 :(得分:1)
在您的查询中,您将别名hit
提供给UNNEST(hits)
返回的元素,将别名customDimension
提供给UNNEST(customDimensions)
返回的元素。如果您想引用特定匹配而不是数组,请改用hit
,如果您想引用单个自定义维度,请改用customDimension
。例如,您的过滤器可能类似于:
WHERE _TABLE_SUFFIX BETWEEN '20161025' AND '20161026' AND
hit.page.hostname LIKE '%website.fr%' AND
customDimension.value != "null" AND
hit.page.pagePath LIKE '%poiu%' AND
hit.type = 'PAGE' AND
customDimension.index IN (1, 11, 14, 27)
答案 1 :(得分:1)
我在查询中发现了几个错误。我做了更正,希望这对你有帮助。
SELECT DATE,MAX(CASE
WHEN customDimensions.index = 1 THEN customDimensions.value END) AS CUSTOMDIMENSIONS_VALUE, visitNumber, fullvisitorid, visitStartTime, TIMESTAMP_SECONDS(visitStartTime) AS humain, EXTRACT(DATE FROM TIMESTAMP_SECONDS(visitStartTime) AT TIME ZONE 'Paris_timezone') AS Paris_timezone,
hits.hour, hits.minute, CONCAT(CAST(fullVisitorId AS string),CAST(visitId AS string)) AS sessionid, MAX(CASE
WHEN customDimensions.index = 11 THEN customDimensions.value END) AS localproductname,
device.deviceCategory,
hits.page.pagePath,
IFNULL(hits.page.pagePathLevel2,'') AS HITS_PAGE_PAGEPATHLEVEL2,
IFNULL(hits.page.pagePathLevel3,'') AS HITS_PAGE_PAGEPATHLEVEL3,
MAX(CASE WHEN customDimensions.index = 14 THEN customDimensions.value END) AS assetpurpose,
MAX(CASE WHEN customDimensions.index = 27 THEN customDimensions.value END) AS pathology,
hits.hitNumber
FROM `85801771.ga_sessions*`
CROSS JOIN UNNEST(customDimensions) AS customDimensions
CROSS JOIN UNNEST(hits) AS hits
WHERE _TABLE_SUFFIX BETWEEN '20161025' AND '20161026'
AND hits.page.hostname LIKE 'website.fr'
AND customDimensions.value != "null"
AND hits.page.pagePath LIKE 'poiu'
AND hits.type = 'PAGE'
AND (customDimensions.index = 1
OR customDimensions.index = 11
OR customDimensions.index = 14
OR customDimensions.index = 27 )
GROUP BY
DATE,
visitStartTime,
humain,
Paris_timezone,
hits.hour,
hits.minute,
fullVisitorId,
sessionid,
visitNumber,
device.deviceCategory,
hits.page.pagePath,
HITS_PAGE_PAGEPATHLEVEL2,
HITS_PAGE_PAGEPATHLEVEL3,
hits.hitNumber
ORDER BY DATE,
visitStartTime,
device.deviceCategory,
humain,
Paris_timezone,
hits.hour,
hits.minute,
fullVisitorId,
sessionid,
visitNumber,
hits.page.pagePath,
HITS_PAGE_PAGEPATHLEVEL2,
HITS_PAGE_PAGEPATHLEVEL3,
hits.hitNumber DESC
LIMIT 100000