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.2KB

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