COMPSCI 280 Computer Science Exercise 13 Solution Exercise 1: List the foods and their prices. Add the message “expensive” or “Good deal” to the foods that cost more than $2. List the foods in alphabetical order. The rows of data are divided into two groups o Price > $2 => “Expensive” o Price <= $2 => “Good deal” Answer: select description, price, 'expensive' as message from L_FOODS where price > 2 UNION ALL select description, price, 'Good deal' from L_FOODS where price <= 2 Or price is null Order by description; Exercise 2: Consider the table1: ITEM SAMSONITE SUITCASE RENT FOR APRIL OPERA TICKET LUNCH DEBT REPAID BY JIM CAR REPAIR HAIRCUT BIRTHDAY GIFT FROM MOM COSTΞΞ -248.13 700 -145 -15.62 20 -622.98 -22 200 and Table2: ITEM BIRTHDAY GIFT FROM MOM CAR REPAIR DEBT REPAID BY JIM HAIRCUT LUNCH OPERA TICKET RENT FOR APRIL SAMSONITE SUITCASE debits null -622.98 null -22 -15.62 -145 null -248.13 credits 200 null 20 null null null 700 null Convert the table1 into the table2 Answer: select item, null as debits, cost as credits from finances where cost > 0 union all select item, cost, null from finances where cost < 0 or cost is null order by item; 1 Exercise 3: Increase the price of all foods costing more than $2 by 5%. Increase the price of all other foods by 10%. Ignore the existing price_increase column. menu_item 1 2 3 4 5 6 7 8 9 10 description Fresh Salad Soup Of The Day Sandwich Grilled Steak Hamburger Broccoli French Fries Soda Coffee Dessert price 2 1.5 3.5 6 2.5 1 1.5 1.25 0.85 3 new_price 2.200000 1.650000 3.675000 6.300000 2.625000 1.100000 1.650000 1.375000 0.935000 3.150000 Answer: select menu_item, description, price + (price * .05) as new_price from l_foods where price > 2.00 or price is null union all select menu_item, description, price + (price * .10) from l_foods where price <= 2.00 order by menu_item; 2
© Copyright 2026 Paperzz