Posted on

How would you adapt this query to obtain cost and impression metrics by supply_source? SELECT device_type, operating_system, SUM(total_cost)/100000 AS total_cost_dollars, ((SUM(total_cost)/100000)/SUM(impressions))*1000 AS avg_cpm, SUM(impressions) AS impressions FROM dsp_impressions GROUP BY 1,2

  • SELECT supply_source, SUM(total_cost)/100000000 AS total_cost_dollars, ((SUM(total_cost)/100000000)/SUM(impressions))*1000 AS avg_cpm, SUM(impressions) AS impressions FROM dsp_inventory GROUP BY 1
  • SELECT supply_source, SUM(total_cost)/100000 AS total_cost_dollars, ((SUM(total_cost)/100000)/SUM(impressions))*1000 AS avg_cpm, SUM(impressions) AS impressions FROM dsp_impressions GROUP BY 1,2
  • SELECT supply_source, SUM(total_cost)/100000 AS total_cost_dollars, ((SUM(total_cost)/100000)/SUM(impressions))*1000 AS avg_cpm, SUM(impressions) AS impressions FROM dsp_impressions GROUP BY 1

The correct answer is:

  • SELECT supply_source, SUM(total_cost)/100000 AS total_cost_dollars, ((SUM(total_cost)/100000)/SUM(impressions))*1000 AS avg_cpm, SUM(impressions) AS impressions FROM dsp_impressions GROUP BY 1,2