Table Schema
Inspect
Table
| Column | Type |
|---|---|
| search_id | integer |
| user_id | integer |
| source | varchar |
| destination | varchar |
| search_time | date |
Find the most frequently searched route.
Table Schema
| Column | Type |
|---|---|
| search_id | integer |
| user_id | integer |
| source | varchar |
| destination | varchar |
| search_time | date |
Sample Data
| search_id | user_id | source | destination | search_time |
|---|---|---|---|---|
| 1 | 101 | A | B | 2024-01-01 |
| 2 | 102 | A | B | 2024-01-01 |
| 3 | 103 | B | C | 2024-01-01 |
| 4 | 104 | A | B | 2024-01-02 |
| 5 | 105 | B | C | 2024-01-02 |
| 6 | 106 | A | D | 2024-01-02 |
| 7 | 107 | A | B | 2024-01-03 |
| 8 | 108 | B | C | 2024-01-03 |
| 9 | 109 | A | B | 2024-01-03 |
| source | destination | count |
|---|---|---|
| A | B | 5 |
SQL Editor
| source | destination | count |
|---|---|---|
| A | B | 5 |
Hints
Solution
Solution is locked until you decide to reveal it. Try the editor first, then open this when you want the reference answer.
SELECT source, destination, COUNT(*) AS count FROM search_routes GROUP BY source, destination ORDER BY count DESC LIMIT 1;
Explanation
Group searches by route.
Count each route search.
Order by frequency and return the most searched route.
Related Questions