82. The top search query on new year's day

easy search engine

Write a query to return the top search term on new year's day: 2021-01-01

Table: search

  col_name| col_type
----------+------------
country   | varchar(2)
date      | date
user_id   | integer
search_id | integer
query     | text


Sample results

top_search_term
--------------------
Joe Biden

Expected results

Solution postgres

SELECT query FROM (
    SELECT
	query,
	COUNT(*)
    FROM search
    WHERE date = '2021-01-01'
    GROUP BY 1
    ORDER BY 2 DESC
    LIMIT 1
) X
    

Explanation

This query is selecting data from a table called "search" and is filtering for data that was recorded on January 1st, 2021. The query is then grouping the data by the "query" column and counting how many times each query appears. The results are then sorted in descending order by the count and the top result is selected (LIMIT 1).

Essentially, this query is finding the most searched query on January 1st, 2021 in the "search" table.


More Search Engine questions

ID Title Level FTPR
81 How many people searched on new year's day search engine easy
24%
83 Top search_query in US and UK on new year's day search engine medium
6%
84 Click through rate on new year's day search engine medium
10%
85 Top 4 queries based on click through rate on new year's day search engine hard
6%
203 Top 5 products by country by month search engine easy -
204 AB testing sanity check search engine easy -
205 Search results recall search engine medium -
206 Search results recall by testing group search engine medium -
207 Results shown rate by group search engine easy -
208 Top 3 urls by testing groups search engine medium -