Consecutive Marketing Touches
Beginner Mode
Objective
Write a SQL query to find contacts who had marketing touches for 3 or more consecutive weeks and had at least one trial_request touch. Output their email addresses in ascending order.
Table Schema:
- marketing_touches
| Column | Type | Description |
|---|---|---|
| contact_id | INTEGER | Unique identifier for the contact |
| VARCHAR | Email address of the contact | |
| touch_date | DATE | Date the marketing touch occurred |
| touch_type | VARCHAR | Type of touch ('page_view', 'email_open', 'trial_request', 'webinar', 'download') |
Task Requirements:
- A "week" is determined by truncating the date to the start of its ISO week (Monday)
- Multiple touches within the same week count as a single week
- The
trial_requesttouch does not need to fall within the consecutive-week streak, it just needs to exist for that contact - Both conditions must be met: 3+ consecutive weeks of touches AND at least one
trial_request - Order results by
emailin ascending order
Output columns: email
Examples
Example 1:
Output:
Input:
| marketing_touches | |||
|---|---|---|---|
| contact_id | touch_date | touch_type | |
| 1 | [email protected] | 2024-01-02 | page_view |
| 1 | [email protected] | 2024-01-10 | email_open |
| 1 | [email protected] | 2024-01-16 | trial_request |
| 2 | [email protected] | 2024-01-03 | page_view |
| 2 | [email protected] | 2024-01-17 | email_open |
| 2 | [email protected] | 2024-01-24 | trial_request |
| 3 | [email protected] | 2024-01-09 | webinar |
| 3 | [email protected] | 2024-01-15 | download |
| 3 | [email protected] | 2024-01-23 | trial_request |
| 3 | [email protected] | 2024-01-30 | page_view |
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 →
Salesforce