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;