Google Data Studio 中的 GROUP BY 查询
GROUP BY query in Google Data Studio
我有一个 table 有几个列,包括售票数量列和销售时间列,
我想知道在任何给定时间售出了多少张票。
例如
time
tickets
10:45
5
10:30
6
10:15
3
10:00
2
11:14
8
11:30
6
这是我写的查询-
SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
SELECT hour(time) as hour, tickets FROM Showtimes_View
group by hour(time)
order by hour
查询运行 好在我MySQL,
问题是,当我在 Google Data Studio 中尝试 运行 它时,出现错误。
尝试在标准 BigQuery 上使用此版本:
SELECT EXTRACT(HOUR from time) AS hour, SUM(tickets) AS num_tickets
FROM Showtimes_View
GROUP BY 1
ORDER BY 1;
您评论说 The query ran well on my MySQL
。查询可能有 运行,但关闭 GROUP BY
严格模式以进行查询 运行 通常不是最佳做法。
跳过删除完整的GROUP BY并使用SUM作为聚合函数
SELECT hour(time) as hour, SUM(tickets) FROM Showtimes_View
group by hour(time)
order by hour
我有一个 table 有几个列,包括售票数量列和销售时间列, 我想知道在任何给定时间售出了多少张票。
例如
time | tickets |
---|---|
10:45 | 5 |
10:30 | 6 |
10:15 | 3 |
10:00 | 2 |
11:14 | 8 |
11:30 | 6 |
这是我写的查询-
SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
SELECT hour(time) as hour, tickets FROM Showtimes_View
group by hour(time)
order by hour
查询运行 好在我MySQL,
尝试在标准 BigQuery 上使用此版本:
SELECT EXTRACT(HOUR from time) AS hour, SUM(tickets) AS num_tickets
FROM Showtimes_View
GROUP BY 1
ORDER BY 1;
您评论说 The query ran well on my MySQL
。查询可能有 运行,但关闭 GROUP BY
严格模式以进行查询 运行 通常不是最佳做法。
跳过删除完整的GROUP BY并使用SUM作为聚合函数
SELECT hour(time) as hour, SUM(tickets) FROM Showtimes_View
group by hour(time)
order by hour