Calculate Shop Visibility Ranking in Search Results
Company: Meta
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: Medium
Interview Round: Onsite
shop_impressions
+------------+---------+----------+--------+
| date | shop_id | position | clicks |
+------------+---------+----------+--------+
| 2024-06-01 | 101 | 1 | 45 |
| 2024-06-01 | 102 | 3 | 12 |
| 2024-06-02 | 101 | 2 | 30 |
| 2024-06-02 | 103 | 1 | 18 |
| 2024-06-03 | 101 | 1 | 55 |
+------------+---------+----------+--------+
##### Scenario
An e-commerce marketplace wants to measure how prominently each shop is shown in search results so that marketing can reward high-visibility sellers.
##### Question
Given table shop_impressions(date, shop_id, position, clicks), write a SQL query that
Calculates each shop’s average daily visibility score defined as 1/position over the past 7 days.
Ranks shops by that average visibility (highest first) and returns shop_id, avg_visibility, rank.
##### Hints
Use window or aggregation over a 7-day rolling window; remember to filter by the latest date available.
Quick Answer: This question evaluates SQL data-manipulation skills including time-windowed aggregations, computation of derived visibility metrics, and ranking operations over event-level impression data.