Daily Leads and Partners

ASKED IN INTERVIEW
2pts
Google

Problem Statement

Google marketing analysts are tracking the efficiency of lead generation across different products. Sometimes, the same lead or partner might be recorded multiple times for the same product on a single day due to different interaction touchpoints.

Your task is to write an SQL query that returns the number of unique leads and unique partners for each date and each product.

Rules:

  • Return the result table containing date_id, make_name, unique_leads, and unique_partners.
  • unique_leads is the count of distinct lead_id values.
  • unique_partners is the count of distinct partner_id values.
  • The results must be returned in descending order by date_id. If dates are the same, sort by make_name in ascending order.
Tests your understanding of
Aggregation, Counting and Distinct

Input Tables

daily_sales
date_id(DATE)make_name(VARCHAR)lead_id(INTEGER)partner_id(INTEGER)
2020-12-08toyota01
2020-12-08toyota10
2020-12-08toyota12
2020-12-07toyota02
2020-12-07toyota01
2020-12-08honda12
2020-12-08honda21
2020-12-07honda01
2020-12-07honda12
2020-12-07honda21
product_metadata
make_name(VARCHAR)region(VARCHAR)
toyotaAPAC
hondaEMEA
googleGLOBAL
lead_source
lead_id(INTEGER)source_channel(VARCHAR)
0Search
1Email
2Social

Expected Output

date_id(DATE)make_name(VARCHAR)unique_leads(INTEGER)unique_partners(INTEGER)
2020-12-08honda22
2020-12-08toyota23
2020-12-07honda32
2020-12-07toyota12

Tags

EasyASKED IN INTERVIEWAggregationCountingDistinct
10-15 min
86%

Hints