Career Hub/Interview questions/Top Monthly Searches
Google logo

Top Monthly Searches

Google·medium·SQL

For each month in 2024, find the top 3 search queries by total search volume. If two queries tie, include all tied queries. Return the month (as the first day of the month), the query, the total number of searches, and the rank.

Schema

search_logs
log_idINTEGER
queryVARCHAR
search_dateDATE
user_idINTEGER
countryVARCHAR

Target output

Target output
monthquerytotal_searchessearch_rank
2024-01-01iphone 1541
2024-01-01super bowl32
2024-01-01wordle today32
2024-01-01nba scores23
2024-02-01valentine gifts41
2024-02-01olympics32
2024-02-01oscars 202423

What this question tests

Tests top-N-per-group with ties, the textbook ranking-function decision. The interviewer is watching which one you pick: ROW_NUMBER drops tied queries, RANK skips positions after a tie, and the prompt as written wants the behaviour only DENSE_RANK gives.

More SQL interview questions

  • Viewership Drop Alert · Netflix · hard
  • Average Shares Per Post · Meta · easy
  • Category Explorers · Amazon · medium
Querysearch_logs
Cmd+Enterto runLoading...
Output

Loading sample data...