我正在尝试接收Google Big Query并计算我如何为伦敦Cycle Helmet GA样本数据复制一些标准报告。我偶然发现的一个简单示例是选择按着陆页分割的收入总和。
嵌套表对我来说是新的,我很难找到使用标准SQL执行此操作或类似操作的任何示例。
如何使用标准SQL完成此操作?或者任何人都可以向我指出任何类似的例子?
更新
抱歉没有提前提供更多细节。我已经取得了一些进展,使我能够发布一些代码。我已经理解了数据结构更好一些,并试图像这样解除嵌套:
#StandardSQL
SELECT Visit_ID, h.page.pagePath AS LandingPage, Sales, Revenue
FROM (
SELECT
visitID AS Visit_ID,
h.hitNumber,
h.page.pagePath
FROM
`project_id.dataset.table`, UNNEST(hits) as h
) AS landingpages
JOIN (
SELECT
fullVisitorId AS Visit_ID, sum(totals.transactions) AS Sales, (sum(totals.transactionRevenue)/1000000) AS Revenue
FROM
`project_id.dataset.table`
WHERE
totals.visits>0
AND totals.transactions>=1
AND totals.transactionRevenue IS NOT NULL
GROUP BY
fullVisitorId
) AS sales
ON landingpages.Visit_ID = sales.Visit_ID
这会引发错误:
No matching signature for operator = for argument types: INT64, STRING. Supported signature: ANY = ANY at [23:4]
我认为这几乎就在那里,但我不明白它试图告诉我什么。我该如何修复此连接?
答案 0 :(得分:1)
operator = for参数类型没有匹配的签名:INT64, STRING。支持的签名:ANY = ANY在[23:4]
我不明白它试图告诉我什么。
你正试图加入两个完全不同的领域的平等 不仅它们的价值不同 - 它们甚至不同类型
df$Id <- as.character(df$Id)
# loop through Ids
for(id in unique(df$Id)){
sub <- unique(df[df$Id == id,])
# check if this Id needs to be manipulated
if(nrow(sub) > 1){
# assign unique Ids
for(j in 1:nrow(sub)){
sub[j,1] <- paste0(sub[j,1],letters[j])
}
# replace old Ids with new Ids
df[df$Id == id, ] <- sub
}
}
如何修复此连接?
尝试以下(我不是GA人[在帖子中添加相应标签],但至少它应该有助于下一步 - 我尽可能地保留/重用原始代码)
Field Name Data Type Description
fullVisitorId STRING The unique visitor ID (also known as client ID).
visitId INTEGER An identifier for this session. This is part of the value usually stored as the _utmb cookie. This is only unique to the user. For a completely unique ID, you should use a combination of fullVisitorId and visitId.
答案 1 :(得分:0)