Advertisement
Vita_Harvey

Proj_002

Apr 22nd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 4.24 KB | None | 0 0
  1.  
  2. Vita Wiebe
  3. IT125
  4. Project #2
  5. */
  6.  
  7. USE ex;
  8.  
  9. # Section 1
  10. # Section 1.1: Use
  11.  
  12. #1, 24 rows returned.
  13. SELECT CONCAT(customer_last_name, ", ", customer_first_name) AS "Customer Name", customer_phone AS "Phone Number"
  14. FROM customers;
  15.  
  16. #2, 24 rows returned.
  17. SELECT customer_last_name AS "Last", customer_first_name AS "first", customer_phone as Phone
  18. FROM customers;
  19.  
  20. #3, 40 rows returned.
  21. SELECT invoice_number AS Invoice, ROUND(invoice_total * 0.01, 2) AS "With Interest"
  22. FROM active_invoices;
  23.  
  24. #4, 8 rows returned.
  25. # Note to self: cannot use aliases in WHERE clause.
  26. SELECT invoice_number AS Invoice, invoice_total AS Total, invoice_due_date AS "Due Date"
  27. FROM active_invoices
  28. WHERE invoice_total > 1000;
  29.  
  30. #5, 5 rows returned.
  31. SELECT DISTINCT terms_id
  32. FROM active_invoices;
  33.  
  34. #6, 2 rows returned.
  35. SELECT invoice_id AS Invoice, invoice_total AS Total, credit_total AS Credit
  36. FROM active_invoices
  37. WHERE invoice_total >= 1000 AND credit_total > 0;
  38.  
  39. #7, 2 rows returned.
  40. SELECT CONCAT(customer_last_name, ", ", customer_first_name) AS "Customer Name", customer_zip AS "Zip Code",
  41.     customer_city AS City
  42. FROM customers
  43. WHERE customer_state = 'IL' AND customer_city = "Normal" or customer_city = "Peoria";
  44.  
  45. #8, 36 rows returned.
  46. SELECT invoice_number AS Invoice, invoice_date AS 'Date', terms_id AS TermsID
  47. FROM active_invoices
  48. WHERE terms_id REGEXP '[2, 3, 4]';
  49.  
  50. #9, 36 rows returned.
  51. SELECT invoice_number AS Invoice, invoice_date AS 'Date', terms_id AS TermsID
  52. FROM active_invoices
  53. WHERE terms_id BETWEEN 2 AND 4;
  54.  
  55. #10, 16 rows returned.
  56. SELECT invoice_number
  57. FROM active_invoices
  58. WHERE invoice_number LIKE '%/%' OR invoice_number LIKE '%-%';
  59.  
  60. #11, 4 rows returned.
  61. SELECT invoice_id AS ID, invoice_total AS Total
  62. FROM null_sample
  63. WHERE invoice_total IS NOT NULL;
  64. # The following is to verify that the results of #11 are reasonable.
  65. SELECT * FROM null_sample;
  66.  
  67. #12, 1 row returned.
  68. SELECT customer_last_name, customer_first_name, customer_phone
  69. FROM customers
  70. WHERE customer_state = 'IN'
  71. ORDER BY customer_last_name, customer_first_name;
  72.  
  73. # the following 2 queries were to verify the results in #12,
  74. # as I thought it odd that only one customer was in Indiana.
  75. SELECT customer_last_name, customer_first_name, customer_phone
  76. FROM customers
  77. WHERE customer_state LIKE '%IN%';
  78. # Returns all the customers, ordered by state.
  79. SELECT *
  80. FROM customers
  81. ORDER BY customer_state;
  82.  
  83. #13, 8 rows returned.
  84. SELECT invoice_number, invoice_due_date AS 'Due Date', invoice_total AS Total
  85. FROM active_invoices
  86. WHERE invoice_total > 1000
  87. ORDER BY invoice_total DESC;
  88.  
  89. #14, 0 rows returned (?!!).
  90. SELECT invoice_id
  91. FROM active_invoices
  92. WHERE (invoice_id = 4) AND (invoice_total BETWEEN 100 AND 2000) AND (invoice_due_date LIKE '2014-07%')
  93. ORDER BY invoice_due_date DESC;
  94. # Attempting to confirm suspect results from #14...
  95. SELECT *
  96. FROM active_invoices
  97. WHERE invoice_due_date LIKE '2014-07%'
  98. ORDER BY invoice_due_date DESC;
  99.  
  100. #15, 2 rows returned.
  101. SELECT customer_last_name, customer_first_name, customer_state
  102. FROM customers
  103. WHERE (customer_last_name LIKE 'R%' OR customer_last_name LIKE 'S%' OR customer_last_name LIKE 'T%')
  104.     AND customer_state IN ('WA', 'CA', 'OR')
  105. ORDER BY customer_state, customer_last_name, customer_first_name;
  106.  
  107. # Section 1.2 Design
  108. /*
  109. Table: AncientCityNames
  110. PK (FK to City table, NN): AncientName CHAR(35) # This would be a red key; can't be NULL.
  111.                                                 # Addt'l ancient city names for the same city would
  112.                                                 # get their own row in this table.
  113. FK (must be NN): ModernName CHAR(35) # This would be a red diamond; solid, as it can't be NULL.  Maps  
  114.         (corresponds) to City table's Name field.
  115. (Composite FK corresponding to Code in Country table, NN): CountryCode CHAR(3)
  116. (Composite FK corresponding to Name field/PK of Country table, NN): CountryName CHAR(52)
  117. Last_Year_Used INT(4) # Can't be NULL (must be NN).
  118. Era ENUM('BCE', 'CE') # Can't be NULL (must be NN).
  119. Mayor_Name CHAR(60) # This can be NULL if they don't have a mayor or similar figurehead.
  120. */
  121.  
  122. # Section 2
  123. /*
  124. Numbers 12, 14, and 15 yielded somewhat suspect results, but as written in my corresponding comments,
  125. I was able to confirm the results were accurate with additional queries.
  126. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement