UPDATESQL

Unit 5, lesson 6 · Unit 5 challenge

Unit 5 review: CASE

Unit 5 challenge: tag every order line

This challenge uses a CASE with several branches, where the order of the branches decides the tag, and a second CASE in ORDER BY to sort the tags in an order that is not alphabetical. A line of 3 desks worth $1,647 is 'bulk', not 'large', because the quantity test comes first.

Example
SELECT order_id, qty, unit_price,
       qty * unit_price AS line_total
FROM order_items
WHERE order_id BETWEEN 116 AND 122
ORDER BY line_total DESC;

Your task

The warehouse tags order lines before packing: 'bulk' when the quantity is 3 or more, otherwise 'large' when the line is worth $200 or more (quantity times unit price), otherwise 'standard'. For orders 116 to 122, return order_id, product_id, qty, line_total and tag. Large lines are packed first because they need a second check, then bulk, then standard; within each tag, highest line_total first, then by order_id.

Tables you will use: order_items

Try it in your browserFree, no sign-up. Your query is checked as you go.