0
我有一个包含字段的数据表:search, search_location, num_searches
。我想放在一起SELECT
语句,将产生100个最流行的search_locations
的列表,通过为所有搜索的num_searches
场SUM()
确定与同search_location
(不管search
字段的值)。我怎样才能做到这一点?使用SQL检索数据集中最流行的查询
我有一个包含字段的数据表:search, search_location, num_searches
。我想放在一起SELECT
语句,将产生100个最流行的search_locations
的列表,通过为所有搜索的num_searches
场SUM()
确定与同search_location
(不管search
字段的值)。我怎样才能做到这一点?使用SQL检索数据集中最流行的查询
您可以使用GROUP BY,一种通过将共享某些相同值的所有行分组来减少表的方法。
SELECT search_location, SUM(num_searches) as total_searches
FROM my_table
GROUP BY search_location
ORDER BY total_searches DESC
LIMIT 100;