Kotomarket showcase: price tiers and the top 5

Kotomarket showcase: price tiers and the top 5

The "Kotomarket" marketplace catalog has a flat products table of cat goods: id, name, category, price (rubles), in_stock (units on hand). The marketing team is building a "Best deals" showcase and asks you to assemble it with a single SELECT query. Showcase requirements: 1. Price tier. Every product gets a price_tier column: products cheaper than 500 ₽ — 'бюджет', from 500 ₽ up to (not including) 1500 ₽ — 'средний', 1500 ₽ and above — 'премиум'. 2. Product selection. Only products that are in stock make the showcase. Of those, marketing wants the ones in the «корм» or «игрушки» category, plus — regardless of category — anything cheaper than 500 ₽. 3. Order. Most expensive first; products with equal prices are ordered by name alphabetically. 4. Size. The showcase holds only the first 5 rows of the selection. Output the columns in this order: name, category, price, price_tier. Row order matters (it is defined by the sort).

Expected output sample

This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables. Your answer must use the same column names as this sample — alias them with AS if needed.

namecategorypriceprice_tier
Туннель «Норка»игрушки990средний
Корм «Сытый кот» 2кгкорм890средний
Сухой корм «Океан» 1кгкорм640средний
PostgreSQLv16

Your query result will appear here

Focus radio
Paused · SomaFM · Fluid