Skip to main content
All Questions

Marketing Campaign Duration.

Easy
Unlock detailed company stats for this questionUpgrade

You are given 3 tables, campaign, user and transaction with the following columns

campaign table:

upsell_campaign_iddate_startdate_end
integertimestamptimestamp

user table:

user_idnameis_eligible_for_upsell_campaign
integerstringboolean

transaction table

transaction_iduser_idproduct_idtransaction_datequantity
integerintegerintegertimestampinteger

Write a SQL query that calculates the average total duration of campaigns.

(Note: a campaign may span multiple date ranges across rows. Sum the total duration per campaign first, then average.)