You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

How-to-retrieve-data-from-a-single-table.sql 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. -- Exercise 1
  2. SELECT product_code, product_name, list_price, discount_percent
  3. FROM products
  4. ORDER BY list_price DESC;
  5. -- Exercise 2
  6. SELECT CONCAT(last_name, ', ', first_name) AS full_name
  7. FROM customers
  8. WHERE last_name >= 'M%'
  9. ORDER BY last_name ASC;
  10. -- Exercise 3
  11. SELECT product_name, list_price, date_added
  12. FROM products
  13. WHERE list_price > 500 AND list_price < 2000
  14. ORDER BY date_added DESC;
  15. -- Exercise 4
  16. SELECT product_name, list_price, discount_percent,
  17. ROUND((discount_percent/100) * list_price, 2) AS discount_amount,
  18. ROUND(list_price - (discount_percent/100) * list_price, 2) AS discount_price
  19. FROM products
  20. ORDER BY discount_price DESC
  21. LIMIT 5;
  22. -- Exercise 5
  23. SELECT item_id, item_price, discount_amount, quantity, item_price * quantity AS price_total,
  24. discount_amount * quantity AS discount_total, (item_price - discount_amount) * quantity AS item_total
  25. FROM order_items
  26. WHERE ((item_price - discount_amount) * quantity) > 500
  27. ORDER BY item_total DESC;
  28. -- Exercise 6
  29. SELECT order_id, order_date, ship_date
  30. FROM orders
  31. WHERE ship_date IS NULL;
  32. -- Exercise 7
  33. SELECT NOW() AS today_unformatted, date_format(NOW(), '%d-%b-%Y') AS today_formatted;
  34. -- Exercise 8
  35. SELECT 100 AS price, 0.07 AS tax_rate, 100 * 0.07 AS tax_amount, 100 + (100 * 0.07) AS total;