Count Daily Customers and Total Call Duration
Beginner Mode
Scenario
You work for a telecommunications company and have been given a table of call records.
Task
Write a Snowflake SQL query that:
- Uses
{{ ref("calls") }}as your source table - Counts the number of distinct customers (
cust_id) per date asnum_customers - Sums the
durationcolumn per date astotal_duration - Groups results by
date
Schema
calls
| Column | Type | Description |
|---|---|---|
| call_id | Integer | Unique identifier for each call |
| cust_id | Integer | Identifier of the customer who made the call |
| date | String | Date when the call was made (YYYY-MM-DD) |
| duration | Integer | Duration of the call in seconds |
Example
calls:
| call_id | cust_id | date | duration |
|---|---|---|---|
| 1 | 101 | 2023-06-01 | 120 |
| 2 | 102 | 2023-06-01 | 300 |
| 3 | 101 | 2023-06-01 | 80 |
| 4 | 103 | 2023-06-02 | 250 |
| 5 | 101 | 2023-06-02 | 190 |
Expected Output:
| date | num_customers | total_duration |
|---|---|---|
| 2023-06-01 | 2 | 500 |
| 2023-06-02 | 2 | 440 |
Note: On 2023-06-01, customer 101 made two calls but is counted only once for
num_customers. All call durations on that date are still summed fortotal_duration.
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 →
Amazon