App Click-Through Rate Analysis
Beginner Mode
Objective
Write a SQL query to calculate the click-through rate (CTR) for each app based on 2022 events data.
Table Schema:
- events
| Column | Type | Description |
|---|---|---|
| event_id | INTEGER | Unique identifier for each event |
| app_id | INTEGER | ID of the app |
| event_type | VARCHAR | Type of event ('impression' or 'click') |
| event_date | DATETIME | Date and time when the event occurred |
Task Requirements:
- Filter only events from the year 2022
- Calculate CTR as (clicks / impressions) * 100 for each app
- Round the CTR to 2 decimal places
- Sort results by app ID in ascending order
Output columns: app_id, ctr
Examples
Example 1:
Output:
Input:
| events | |||
|---|---|---|---|
| app_id | event_date | event_id | event_type |
| 101 | 2022-01-15 10:00:00 | 1 | impression |
| 101 | 2022-01-15 10:05:00 | 2 | click |
| 101 | 2022-01-16 11:00:00 | 3 | impression |
| 102 | 2022-02-10 09:00:00 | 4 | impression |
| 102 | 2022-02-10 09:30:00 | 5 | impression |
| 102 | 2022-02-10 10:00:00 | 6 | click |
| app_id | ctr |
|---|---|
| 101 | 50 |
| 102 | 50 |
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
Meta