2016-09-26 22 views
0

與此answer in mind我試圖查詢ga_sessions,加入到我自己的自定義報告計劃後總結一些基本指標。自定義報告時間表將自定義時間段(大約4周)映射到日期格式YYYYMMDD,並位於其自己的表中。加入日期分區表給出「'the_date'不存在於GROUP BY列表」錯誤

下面是我想出什麼了:

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 

但是這給了錯誤:「錯誤:表達式‘the_date’是不存在GROUP BY列表」

我強烈懷疑有我對語法的使用出了問題,我對Google Big Query頗感興趣,查詢日期分區表和連接的組合正在拋出我。

需要更改哪些內容才能更正代碼並按照自定義期間對指標進行求和?

回答

2

您遇到了多個問題。首先,使用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 | | 
+-----+----------+--------+-----------+--------------+---------+---+ 
+0

謝謝,工作一個魅力!並設法適應它沒有問題。 – goose