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 889B

1234567891011121314151617181920212223242526272829303132333435363738
  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
  10. -- Exercise 3
  11. SELECT product_name, list_price, date_added
  12. FROM products
  13. WHERE list_price BETWEEN 500 AND 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. -- Exercise 6
  24. SELECT order_id, order_date, ship_date
  25. FROM orders
  26. WHERE ship_date IS NULL
  27. -- Exercise 7
  28. -- Exercise 8
  29. SELECT '100 (dollars)' AS price, '.07 (7 percent)' AS tax_rate, 7.00 AS tax_amount, 100 + (100 * 0.07) AS total