我第一次使用窗口函数。我有一个基本的窗口函数,我想将结果按介质分组,当我这样做时,我得到了错误:
Error: SELECT list expression references totals.visits which is neither grouped nor aggregated at [1:12]
在我看来,我已经在第一行总结了totals.visits,我在这里遗漏了什么?我希望看到按国家分列的访问总数,例如:
VISITS COUNTRY
1500 United Kingdom
750 Ireland
etc.以下是我的疑问:
SELECT
SUM(totals.visits) OVER(PARTITION BY geoNetwork.country
ORDER BY geoNetwork.country) AS Visits_by_Medium,
trafficSource.medium AS Medium
FROM `xxx.ga_sessions_20171010`
GROUP BY Medium发布于 2017-10-11 10:25:15
我认为您只需要一个简单的GROUP BY查询:
SELECT
SUM(totals.visits) AS VISITS,
geoNetwork.country
FROM xxx.ga_sessions_20171010
GROUP BY
geoNetwork.country;编辑:
运行以下查询,查看作为窗口函数的sum将返回什么:
SELECT
SUM(totals.visits) OVER(PARTITION BY geoNetwork.country
ORDER BY geoNetwork.country) AS Visits_by_Medium,
trafficSource.medium AS Medium
FROM xxx.ga_sessions_20171010;https://stackoverflow.com/questions/46685415
复制相似问题