开发者

Using SQL to retrieve the most popular queries in a dataset

开发者 https://www.devze.com 2023-04-07 18:52 出处:网络
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开发者_高级运维,

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消