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

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