我如何在 Google BigQuery 中按日期趋势 KPI 与媒介和来源?

How can I trend KPI's with Medium & Source by date in Google BigQuery?

我想按特定标准对自定义营销渠道进行编码,例如以下日期:

SELECT
date, 
trafficSource.medium,
case
when trafficSource.medium like '%cpc%' then 'Paid Search'
end as channel
FROM `xyz.ga_sessions_2017*`
limit 1000  

这给了我

的结果
date       |   medium   |   channel
--------------------------------------
20171212   |     cpc    |  Paid Search  

我也可以这样趋势我的 KPI

SELECT
date,
SUM(totals.visits) visits,
SUM(totals.pageviews) pageviews,
SUM(totals.transactions) transactions,
SUM(totals.transactionRevenue)/1000000 revenue
FROM `xyz.ga_sessions_2017*`
GROUP BY
date
ORDER BY
date ASC

这给了我这个结果

date       |   visits   |    pageviews  |   transactions  | revenue
--------------------------------------------------------------------
20171212   |    1234    |      5678     |     1111        | 99999  

但是我的 objective 是将这两个放在一起,看起来应该是这样的:

date     | medium  |   channel     | visits |    pageviews  |   transactions  | revenue
-----------------------------------------------------------------------------------------
20171211 |  cpc    | Paid Search   |  18    |      50       |     17          |    2578  
20171212 |  cpc    | Paid Search   |  27    |      90       |     35          |    2981

有什么提示或建议吗?

以下适用于 BigQuery 标准 SQL

#standardSQL
SELECT
  DATE, 
  trafficSource.medium,
  CASE 
    WHEN trafficSource.medium LIKE '%cpc%' THEN 'Paid Search'
    ELSE trafficSource.medium
  END AS channel,
  SUM(totals.visits) visits,
  SUM(totals.pageviews) pageviews,
  SUM(totals.transactions) transactions,
  SUM(totals.transactionRevenue)/1000000 revenue  
FROM `xyz.ga_sessions_2017*`
GROUP BY DATE, medium, channel
ORDER BY DATE ASC
LIMIT 1000