Cheapest channel per campaign

ranking

Cheapest channel per campaign

Nykaa SQL Interview Question

Nykaa moves budget toward whichever channel buys a campaign's orders most cheaply, and that answer differs by campaign: influencers work for a launch, search works for a repeat purchase. The measure is money spent per order the channel brought in, worked out over the whole run rather than one day.

For each campaign, return the campaign, the channel with the lowest cost per order, and that figure as cost_per_order, rounded to 2 decimal places.

Asked of

  • Data Analyst
  • Business Analyst
  • BI Analyst
  • Product Analyst
  • Analytics Engineer
  • Data Scientist

nykaa_campaign_spendTable24 rows

Column NameType
spend_idBIGINT
campaignVARCHAR
channelVARCHAR
spend_onDATE
spendDOUBLE
attributed_ordersBIGINT

nykaa_campaign_spendExample Input

spend_idcampaignchannelspend_onspendattributed_orders
4109Monsoon CareSearch2024-05-0138000266
4110Monsoon CareSocial2024-05-0141000255
4111Monsoon CareInfluencer2024-05-0152000140
4112Monsoon CareSearch2024-05-0239500281
4113Monsoon CareSocial2024-05-0243000262
4114Monsoon CareInfluencer2024-05-0255000158
4117Festive KajalSearch2024-05-0172000540
4118Festive KajalSocial2024-05-0195000612
4119Festive KajalSearch2024-05-0274500558
4120Festive KajalSocial2024-05-0292000601
4121Festive KajalInfluencer2024-05-02120000330

Example Output

campaignchannelcost_per_order
Festive KajalSearch133.42
Monsoon CareSearch141.68

Explanation

Search buys orders most cheaply in both campaigns in the example, at 133.42 and 141.68 for each order. The figure comes from the total spend over the total orders, not from averaging the daily numbers.

The example above is a small slice of the data. Your query runs against the full tables.