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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. -- Exercise 1
  2. SELECT
  3. product_code,
  4. product_name,
  5. list_price,
  6. discount_percent
  7. FROM products
  8. ORDER BY list_price;
  9. -- Exercise 2
  10. SELECT CONCAT(last_name, ', ', first_name) AS full_name
  11. FROM customers
  12. WHERE last_name >= 'M%'
  13. ORDER BY last_name ASC;
  14. -- Exercise 3
  15. SELECT
  16. product_name,
  17. list_price,
  18. date_added
  19. FROM products
  20. WHERE list_price > 500 AND list_price < 2000
  21. ORDER BY date_added DESC;
  22. -- Exercise 4
  23. SELECT
  24. product_name,
  25. list_price,
  26. discount_percent,
  27. round(list_price * discount_percent/100, 2) AS discount_amount,
  28. round(list_price - list_price * discount_percent/100, 2) AS discount_price
  29. FROM products
  30. ORDER BY discount_price DESC
  31. LIMIT 5;
  32. -- Exercise 5
  33. SELECT
  34. item_id,
  35. item_price,
  36. discount_amount,
  37. quantity,
  38. item_price * quantity AS price_total,
  39. discount_amount * quantity AS discount_total,
  40. (item_price - discount_amount) * quantity AS item_total
  41. FROM order_items
  42. WHERE ((item_price - discount_amount) * quantity) > 500
  43. ORDER BY item_total DESC;
  44. -- Exercise 6
  45. SELECT
  46. order_id,
  47. order_date,
  48. ship_date
  49. FROM orders
  50. WHERE ship_date IS NULL;
  51. -- Exercise 7
  52. SELECT NOW() AS today_unformatted,
  53. date_format(NOW(), '%d-%b-%Y') AS today_formatted;
  54. -- Exercise 8
  55. SELECT 100 AS price,
  56. 0.07 AS tax_rate,
  57. 100 * 0.07 AS tax_amount,
  58. 100 + (100 * 0.07) AS total;