# standardSQL
SELECT EventDate,
b.total_sents - a.total_sents AS total_sents_diff,
b.total_bounces - a.total_bounces AS total_bounces_diff,
b.total_opens - a.total_opens AS total_opens_diff,
b.total_clicks - a.total_clicks AS total_clicks_diff
FROM (
SELECT EventDate,
SUM(IF(EventType IN ('Bounce', 'Open'), EventCount, 0)) AS total_sents,
SUM(IF(EventType = 'Bounce', EventCount, 0)) AS total_bounces,
SUM(IF(EventType = 'Open', EventCount, 0)) AS total_opens,
SUM(IF(EventType = 'Click', EventCount, 0)) AS total_clicks
FROM `project.dataset.tableA`
GROUP BY EventDate
) a
LEFT JOIN `project.dataset.tableB` b
USING(EventDate)
您可以使用下面的示例中的问题中的示例数据来测试、播放上述内容
# standardSQL
WITH `project.dataset.tableA` AS (
SELECT '2020-07-05' EventDate, 'Bounce' EventType, 6 EventCount UNION ALL
SELECT '2020-07-05', 'Click', 16737 UNION ALL
SELECT '2020-07-05', 'Open', 187400 UNION ALL
SELECT '2020-07-06', 'Bounce', 16 UNION ALL
SELECT '2020-07-06', 'Click', 26737 UNION ALL
SELECT '2020-07-06', 'Open', 387400
), `project.dataset.tableB` AS (
SELECT '2020-07-05' EventDate, 155057 total_sents, 166 total_bounces, 75361 total_opens, 8783 total_clicks UNION ALL
SELECT '2020-07-06', 255057, 266, 85361, 9783
)
SELECT EventDate,
b.total_sents - a.total_sents AS total_sents_diff,
b.total_bounces - a.total_bounces AS total_bounces_diff,
b.total_opens - a.total_opens AS total_opens_diff,
b.total_clicks - a.total_clicks AS total_clicks_diff
FROM (
SELECT EventDate,
SUM(IF(EventType IN ('Bounce', 'Open'), EventCount, 0)) AS total_sents,
SUM(IF(EventType = 'Bounce', EventCount, 0)) AS total_bounces,
SUM(IF(EventType = 'Open', EventCount, 0)) AS total_opens,
SUM(IF(EventType = 'Click', EventCount, 0)) AS total_clicks
FROM `project.dataset.tableA`
GROUP BY EventDate
) a
LEFT JOIN `project.dataset.tableB` b
USING(EventDate)
1条答案
按热度按时间6g8kf2rb1#
下面是bigquery标准sql
您可以使用下面的示例中的问题中的示例数据来测试、播放上述内容
有输出