How would you adapt this query to obtain cost and impression metrics by supply_source?
Choose an answer
Tap an option to check your answer.
Correct answer: 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.
Why this is the answer
The correct query aggregates cost and impression data from the dspimpressions table by supplysource. It calculates totalcostdollars by dividing totalcost by 100,000 to convert from micro-dollars to dollars, and avgcpm (average cost per mille/thousand impressions) by dividing the dollar cost by total impressions and multiplying by 1000. It also sums impressions. The GROUP BY 1 clause correctly groups the results by the first selected column, supplysource. The first incorrect option uses dspinventory instead of dspimpressions, which is not the correct table for impression-level data. It also divides totalcost by 100,000,000, which is an incorrect conversion factor. The second incorrect option uses the correct table and conversion factor but includes GROUP BY 1,2, which would group by supplysource and totalcostdollars, leading to incorrect aggregation for avgcpm and impressions as totalcostdollars is an aggregated metric itself.
Pass your exam — without the endless answer hunt
Get every verified question and explanation for this exam in one place, and save hours of prep. 1,000+ certifications · 20+ languages · free to start.
Pass your exam faster → No card needed