如何左连接自定义维度和事务
How to left join both custom dimensions and transactions
我保留了自定义维度(用户 ID 和商家)的联接值。我还想添加交易。我可以就如何将其添加到此查询中获得一些建议吗?还是我必须完全改变结构?这就是我尝试的方式,但我收到一个语法错误,提示它需要 FROM 语句所在的结束输入。
merchants.merchant_Id,
otherMerchants.merchant_id AS otherMerchants,
merchants.market AS market,
COUNT (merchants.transactions) AS transactions,
COUNT(DISTINCT merchants.userId) users
FROM(
SELECT
#här hämtar vi alla userIds och merchantIds
(SELECT VALUE FROM UNNEST(customDimensions) WHERE INDEX = 3) userid,
(SELECT VALUE FROM UNNEST(customDimensions) WHERE INDEX = 4) merchant_Id,
(SELECT VALUE FROM UNNEST (customDimensions) WHERE INDEX = 8) market,
hits.transaction.transactionId) as transactions
FROM `qliro-66ee8.128389777.ga_sessions_20210628`
UNNEST (hits) AS hits
) merchants
LEFT JOIN
(
SELECT
#här hämtar vi alla userIds och merchantIds igen för att kunna nyckla ihop det
(SELECT VALUE FROM UNNEST(customDimensions) WHERE INDEX = 3) userid,
(SELECT VALUE FROM UNNEST(customDimensions) WHERE INDEX = 4) merchant_id,
(SELECT VALUE FROM UNNEST (customDimensions) WHERE INDEX = 8) market,
hits.transaction.transactionId) as transactions
FROM `qliro-66ee8.128389777.ga_sessions_20210628`
UNNEST (hits) AS hits
) otherMerchants
#nycklar på att det är samma user samt inte samma merchant för att inte få dubbelräkning
#nycklar på att det är samma user samt inte samma merchant för att inte få dubbelräkning
ON merchants.userId = otherMerchants.userid
AND merchants.merchant_Id != otherMerchants.merchant_id
AND merchants.transactions = otherMerchants.transactions
AND merchants.market = otherMerchants.market
GROUP BY 1,2,3
我认为你非常接近!你应该这样做
SELECT
merchants.merchant_Id,
otherMerchants.merchant_id AS otherMerchants,
merchants.market AS market,
SUM(merchants.transactions) AS transactions,
COUNT(DISTINCT merchants.userId) users
FROM(
SELECT
(SELECT VALUE FROM UNNEST(t1.customDimensions) WHERE INDEX = 3) userid,
(SELECT VALUE FROM UNNEST(t1.customDimensions) WHERE INDEX = 4) merchant_Id,
(SELECT VALUE FROM UNNEST (t1.customDimensions) WHERE INDEX = 8) market,
count(distinct hits.transaction.transactionId) as transactions
FROM `qliro-66ee8.128389777.ga_sessions_20210628` t1,
UNNEST (hits) AS hits
GROUP BY 1,2,3
) merchants
LEFT JOIN
(
SELECT
#här hämtar vi alla userIds och merchantIds igen för att kunna nyckla ihop det
(SELECT VALUE FROM UNNEST(customDimensions) WHERE INDEX = 3) userid,
(SELECT VALUE FROM UNNEST(customDimensions) WHERE INDEX = 4) merchant_id,
(SELECT VALUE FROM UNNEST (customDimensions) WHERE INDEX = 8) market
FROM `qliro-66ee8.128389777.ga_sessions_20210628`
) otherMerchants
ON merchants.userId = otherMerchants.userid
AND merchants.merchant_Id != otherMerchants.merchant_id
AND merchants.market = otherMerchants.market
GROUP BY 1,2,3
编辑:查询中缺少 GROUP BY 语句
我保留了自定义维度(用户 ID 和商家)的联接值。我还想添加交易。我可以就如何将其添加到此查询中获得一些建议吗?还是我必须完全改变结构?这就是我尝试的方式,但我收到一个语法错误,提示它需要 FROM 语句所在的结束输入。
merchants.merchant_Id,
otherMerchants.merchant_id AS otherMerchants,
merchants.market AS market,
COUNT (merchants.transactions) AS transactions,
COUNT(DISTINCT merchants.userId) users
FROM(
SELECT
#här hämtar vi alla userIds och merchantIds
(SELECT VALUE FROM UNNEST(customDimensions) WHERE INDEX = 3) userid,
(SELECT VALUE FROM UNNEST(customDimensions) WHERE INDEX = 4) merchant_Id,
(SELECT VALUE FROM UNNEST (customDimensions) WHERE INDEX = 8) market,
hits.transaction.transactionId) as transactions
FROM `qliro-66ee8.128389777.ga_sessions_20210628`
UNNEST (hits) AS hits
) merchants
LEFT JOIN
(
SELECT
#här hämtar vi alla userIds och merchantIds igen för att kunna nyckla ihop det
(SELECT VALUE FROM UNNEST(customDimensions) WHERE INDEX = 3) userid,
(SELECT VALUE FROM UNNEST(customDimensions) WHERE INDEX = 4) merchant_id,
(SELECT VALUE FROM UNNEST (customDimensions) WHERE INDEX = 8) market,
hits.transaction.transactionId) as transactions
FROM `qliro-66ee8.128389777.ga_sessions_20210628`
UNNEST (hits) AS hits
) otherMerchants
#nycklar på att det är samma user samt inte samma merchant för att inte få dubbelräkning
#nycklar på att det är samma user samt inte samma merchant för att inte få dubbelräkning
ON merchants.userId = otherMerchants.userid
AND merchants.merchant_Id != otherMerchants.merchant_id
AND merchants.transactions = otherMerchants.transactions
AND merchants.market = otherMerchants.market
GROUP BY 1,2,3
我认为你非常接近!你应该这样做
SELECT
merchants.merchant_Id,
otherMerchants.merchant_id AS otherMerchants,
merchants.market AS market,
SUM(merchants.transactions) AS transactions,
COUNT(DISTINCT merchants.userId) users
FROM(
SELECT
(SELECT VALUE FROM UNNEST(t1.customDimensions) WHERE INDEX = 3) userid,
(SELECT VALUE FROM UNNEST(t1.customDimensions) WHERE INDEX = 4) merchant_Id,
(SELECT VALUE FROM UNNEST (t1.customDimensions) WHERE INDEX = 8) market,
count(distinct hits.transaction.transactionId) as transactions
FROM `qliro-66ee8.128389777.ga_sessions_20210628` t1,
UNNEST (hits) AS hits
GROUP BY 1,2,3
) merchants
LEFT JOIN
(
SELECT
#här hämtar vi alla userIds och merchantIds igen för att kunna nyckla ihop det
(SELECT VALUE FROM UNNEST(customDimensions) WHERE INDEX = 3) userid,
(SELECT VALUE FROM UNNEST(customDimensions) WHERE INDEX = 4) merchant_id,
(SELECT VALUE FROM UNNEST (customDimensions) WHERE INDEX = 8) market
FROM `qliro-66ee8.128389777.ga_sessions_20210628`
) otherMerchants
ON merchants.userId = otherMerchants.userid
AND merchants.merchant_Id != otherMerchants.merchant_id
AND merchants.market = otherMerchants.market
GROUP BY 1,2,3
编辑:查询中缺少 GROUP BY 语句