将旧版BigQuery转换为Standard并得到错误“无法解析表名称“ s3”:数据集名称丢失。”

时间:2018-10-02 15:01:43

标签: google-analytics google-bigquery

错误在第4行,并且s3.fullVisitorId带下划线。我想这会在该组中的每个选定项目上引发错误。

我尝试在DISTINCT之后添加SELECT语句,但内联错误消失了,但是当我尝试运行查询时,出现错误:“表名称“ s3”无法解析:数据集名称丢失。”

任何帮助将不胜感激。我发现将查询从传统sql转换为标准sql有点麻烦。

这是完整的查询:

#standardSQL
SELECT
  CAST(CONCAT(SUBSTR(date,1,4),'-',SUBSTR(date,5,2),'-',SUBSTR(date,7,2)) AS DATE) AS Date,
  COUNT(DISTINCT s3.fullVisitorId) AS users,
  COUNT(s0.firstHit) AS carts,
  COUNT(s1.firstHit) AS order_details,
  COUNT(s2.firstHit) AS order_confirmation
FROM (
  SELECT
    IFNULL(s3.date,
      IFNULL(s0.date,
        IFNULL(s1.date,
          s2.date))) AS date,
    s3.fullVisitorId,
    s0.fullVisitorId,
    s0.visitId,
    s0.firstHit,
    s1.firstHit,
    s2.firstHit
  FROM (
      # user subquery
    SELECT
      date,
      fullVisitorId,
      visitId
    FROM
      `big-query-project-34643.162968675.ga_sessions_*`
    WHERE
      _TABLE_SUFFIX BETWEEN FORMAT_DATE('%Y%m%d', DATE_SUB(CURRENT_DATE(), INTERVAL 365 DAY))
      AND FORMAT_DATE('%Y%m%d', DATE_SUB(CURRENT_DATE(), INTERVAL 0 DAY))
      AND totals.visits = 1
    GROUP BY
      date,
      fullVisitorId,
      visitId) s3
  FULL OUTER JOIN
    ((
      # first subquery
    SELECT
      date,
      fullVisitorId,
      visitId,
      MIN(h.hitNumber) AS firstHit
    FROM
      `big-query-project-34643.162968675.ga_sessions_*`, unnest(hits) as h
    WHERE
      _TABLE_SUFFIX BETWEEN FORMAT_DATE('%Y%m%d', DATE_SUB(CURRENT_DATE(), INTERVAL 365 DAY))
      AND FORMAT_DATE('%Y%m%d', DATE_SUB(CURRENT_DATE(), INTERVAL 0 DAY))
      AND REGEXP_CONTAINS(h.page.pagePath,
        '/cart')
      AND totals.visits = 1
    GROUP BY
      date,
      fullVisitorId,
      visitId)) s0
  ON
    s3.fullVisitorId = s0.fullVisitorId
    AND s3.visitId = s0.visitId
  FULL OUTER JOIN
     ((
      # Second Subquery
    SELECT
      date,
      fullVisitorId,
      visitId,
      MIN(h.hitNumber) AS firstHit
    FROM
      `big-query-project-34643.162968675.ga_sessions_*`, unnest(hits) as h
    WHERE
      _TABLE_SUFFIX BETWEEN FORMAT_DATE('%Y%m%d', DATE_SUB(CURRENT_DATE(), INTERVAL 365 DAY))
      AND FORMAT_DATE('%Y%m%d', DATE_SUB(CURRENT_DATE(), INTERVAL 0 DAY))
      AND REGEXP_CONTAINS(h.page.pagePath,
        '/order-details')
      AND totals.visits = 1
    GROUP BY
      date,
      fullVisitorId,
      visitId)) s1
  ON
    s0.fullVisitorId = s1.fullVisitorId
    AND s0.visitId = s1.visitId
  FULL OUTER JOIN
     ((
      # Third Subquery
    SELECT
      date,
      fullVisitorId,
      visitId,
      MIN(h.hitNumber) AS firstHit
    FROM
      `big-query-project-34643.162968675.ga_sessions_*`, unnest(hits) as h
    WHERE
      _TABLE_SUFFIX BETWEEN FORMAT_DATE('%Y%m%d', DATE_SUB(CURRENT_DATE(), INTERVAL 365 DAY))
      AND FORMAT_DATE('%Y%m%d', DATE_SUB(CURRENT_DATE(), INTERVAL 0 DAY))
      AND REGEXP_CONTAINS(h.page.pagePath,
        '/orderconfirmation')
      AND totals.visits = 1
    GROUP BY
      date,
      fullVisitorId,
      visitId)) s2
  ON
    s1.fullVisitorId = s2.fullVisitorId
    AND s1.visitId = s2.visitId)
GROUP BY
  date
ORDER BY
  date

1 个答案:

答案 0 :(得分:2)

您这里有多个问题-尤其是:第14-19行

s3.fullVisitorId,
s0.fullVisitorId,
s0.visitId,
s0.firstHit,
s1.firstHit,
s2.firstHit

我建议至少提供以下[例如]的别名

s3.fullVisitorId s3_fullVisitorId,
s0.fullVisitorId s0_fullVisitorId,
s0.visitId,
s0.firstHit s0_firstHit,
s1.firstHit s1_firstHit,
s2.firstHit s2_firstHit    

然后在第4-7行-引用别名

COUNT(DISTINCT s3_fullVisitorId) AS users,
COUNT(s0_firstHit) AS carts,
COUNT(s1_firstHit) AS order_details,
COUNT(s2_firstHit) AS order_confirmation