#42

Top 5 Single-Channel Media Types by Promotional Spend

EASYAggregation & RankingPOSTGRESQL

Problem Description

You are building a marketing analytics pipeline for a grocery chain's promotions team. The marketing team tracks spend across various promotional media types — such as TV, Radio, Internet, Billboard, and Direct Mail — in a `promotions` table. Each promotion record captures the media channel used and its associated cost. The team needs a summary of the top 5 single-channel promotional spend categories to guide quarterly budget allocation decisions. Your task is to aggregate total promotional spend by `media_type`, return the top 5 by total cost in descending order, and exclude any rows where `media_type` is NULL. Return `media_type` and `total_cost` (the sum of all promotion costs for that media type), ordered from highest to lowest spend. If fewer than 5 distinct media types exist, return all of them. **Output columns:** `media_type`, `total_cost` Break ties in total cost by `media_type` ascending (alphabetical).

Topics

rankinggrouping

Asked at Companies

meta

Solve This Problem

Sign up to access the interactive code editor, run test cases, view the editorial, and get AI-powered feedback on your solution.

Start Solving →