I have a table of data with fields: search, search_location, num_searches
. I want to put together a SELECT
statement that will generate a list of the 100 most popular search_locations开发者_高级运维
, determined by the SUM()
of the num_searches
field for all searches with the same search_location
(regardless of the value of the search
field). How can I accomplish this?
You can use a GROUP BY, a method that reduces a table by grouping all rows that share some of the same values.
SELECT search_location, SUM(num_searches) as total_searches
FROM my_table
GROUP BY search_location
ORDER BY total_searches DESC
LIMIT 100;
精彩评论