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

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