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

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. -- Exercise 3
  9. SELECT product_name,list_price,date_added
  10. FROM products
  11. WHERE list_price > 500 AND list_price < 1200
  12. ORDER BY date_added DESC;
  13. -- Exercise 4
  14. SELECT product_name,list_price,discount_percent,(list_price*discount_percent/100)AS discount_amount,(list_price -(list_price*discount_percent/100))AS discount_price
  15. FROM products
  16. ORDER BY list_price DESC LIMIT 5;
  17. -- Exercise 5
  18. SELECT item_id,item_price,discount_amount,quantity,(item_price*quantity)AS price_total,(discount_amount*quantity)AS discount_total,(item_price*quantity)-(discount_amount*quantity)AS item_total
  19. FROM order_items
  20. ORDER BY item_price DESC LIMIT 5;
  21. -- Exercise 6
  22. SELECT order_id,order_date,ship_date
  23. FROM orders
  24. WHERE ship_date IS null;
  25. -- Exercise 7
  26. SELECT NOW()=today_unformatted,
  27. (DD-Mon-YYYY)=today_formatted;
  28. -- Exercise 8
  29. SELECT list_price as price,
  30. discount_percent as tax_rate,
  31. (list_price*discount_percent/100) AS tax_amount,
  32. list_price*(list_price*discount_percent/100) AS total
  33. FROM products;