Consecutive Marketing Touches
Salesforce 🧠 Hard SQL
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
email 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_request touch 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 email in ascending order

Output columns: email

Examples

Example 1:

Input:

marketing_touches
contact_idemailtouch_datetouch_type
1[email protected]2024-01-02page_view
1[email protected]2024-01-10email_open
1[email protected]2024-01-16trial_request
2[email protected]2024-01-03page_view
2[email protected]2024-01-17email_open
2[email protected]2024-01-24trial_request
3[email protected]2024-01-09webinar
3[email protected]2024-01-15download
3[email protected]2024-01-23trial_request
3[email protected]2024-01-30page_view

Output:
Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →