【问题标题】:Joining date partitioned table give "'the_date' is not present in the GROUP BY list" error加入日期分区表给出“'the_date' is not present in the GROUP BY list”错误
【发布时间】:2016-09-26 19:11:33
【问题描述】:

通过answer in mind,我正在尝试查询 ga_sessions,在加入我自己的自定义报告计划后汇总一些基本指标。自定义报告计划将自定义期间(大约 4 周)映射到日期格式 YYYYMMDD 并在其自己的表格中。

这是我想出的:

SELECT
  schedule.period,
  gadata.Visits,
  gadata.Pageviews,
  gadata.Transactions,
  gadata.Revenue
FROM (
  SELECT 
    gadata.date AS the_date, 
    SUM(totals.visits) AS Visits, 
    SUM(totals.pageviews) AS Pageviews,
    SUM(totals.transactions) AS Transactions, 
    SUM(totals.transactionRevenue)/1000000 AS Revenue
  FROM TABLE_DATE_RANGE([project.table_prefix_],TIMESTAMP('2013-09-10'),TIMESTAMP('2013-09-12'))
  GROUP BY
    gadata.the_date
  ORDER BY
    gadata.the_date ASC
) AS gadata
JOIN 
  [project.reporting_schedule] AS schedule
ON
  gadata.date = schedule.GA_Date
GROUP BY gadata.the_date

但这给出了错误:“错误:GROUP BY 列表中不存在表达式'the_date'”

我强烈怀疑我对语法的使用有问题,我对 Google Big Query 很陌生,查询日期分区表和连接的组合让我很吃惊。

我需要更改哪些内容才能更正代码并按自定义期间汇总指标?

【问题讨论】:

    标签: google-bigquery


    【解决方案1】:

    您遇到了多个问题。首先是 Table 日期范围函数不能使用别名,因此您需要包装成一个 select 以进一步使用别名。

    我用静态写法替换了scheduled表,但是你可以用自己的select field from table语法替换

    SELECT
      the_date,
      SUM(totals.visits) AS Visits,
      SUM(totals.pageviews) AS Pageviews,
      SUM(totals.transactions) AS Transactions,
      SUM(totals.transactionRevenue)/1000000 AS Revenue
    FROM (
      SELECT
        [date] AS the_date,
        totals.visits,
        totals.pageviews,
        totals.transactions,
        totals.transactionRevenue
      FROM
        TABLE_DATE_RANGE([google.com:analytics-bigquery:LondonCycleHelmet.ga_sessions_],TIMESTAMP('2013-09-10'),TIMESTAMP('2013-09-12')) ) tt
    JOIN (
      SELECT * FROM (SELECT '20130910' AS report_date), (SELECT '20130911' AS report_date)) schedule
    ON
      schedule.report_date = tt.the_date
    GROUP BY
      1
    

    返回:

    +-----+----------+--------+-----------+--------------+---------+---+
    | Row | the_date | Visits | Pageviews | Transactions | Revenue |   |
    +-----+----------+--------+-----------+--------------+---------+---+
    |   1 | 20130910 |     63 |       249 |           16 | 206.23  |   |
    +-----+----------+--------+-----------+--------------+---------+---+
    

    【讨论】:

    • 谢谢,很有魅力!并设法毫无问题地适应它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-08
    • 2019-03-11
    • 2019-09-22
    • 1970-01-01
    • 1970-01-01
    • 2018-07-16
    相关资源
    最近更新 更多