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

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