All problems

Category Price Positioning

easySQLGroupByAggregation

The pricing team at Whetcode Supply is deciding which categories to push in the next campaign and wants to know how premium each one currently reads. The measure they have settled on is the typical price of an item in that category — one figure per category, most premium first.

Note that this is about the catalogue, not about sales. A category can look premium and sell nothing, which is exactly the tension the campaign is meant to resolve.

products — the catalogue, one row per item on sale. price is what a single unit costs, in dollars.

id name category price
1 Wireless Mouse electronics 25.0
2 Standing Desk furniture 350.0
3 Desk Lamp furniture 40.0
4 Mechanical Keyboard electronics 85.0
5 Notebook Set office 12.0

The table already exists in the database — there is nothing to create or load.

Task: Write a query returning two columns, category and avg_price (the mean price of the items in that category, rounded to two decimal places), one row per category that has at least one product, highest mean first. Round the finished mean rather than each price on the way in. No two categories share a mean here.

Example output — shape only, on invented figures. The category labels are the real stored ones; a mean that does not land on a round number keeps its cents:

category avg_price
office 148.5
electronics 121.5
furniture 9.33

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…