########################################## # # MySQL (1) : In class exercise # # Use the sample database (sample_data.sql) # if you are required to use a database # ########################################## ###### Question No. 1 ################################################## ########################################## # # Normalize the following table on paper: # # +----------------+--------------------+-------------+-------------+---------------+------------+ # | p_name | p_phone | p_tx_1 | p_tx_2 | doc_name | doc_office | # +----------------+--------------------+-------------+-------------+---------------+------------+ # | David Harrison | 456-9900, 898-8877 | | | Robert Chen | 455 | # | Eric Lee | 456-5455 | Asprin | Methadon | Robert Chen | 455 | # | Peter Jackson | 456-8978, 675-9989 | Asprin | Diazepam | Sara Robinson | 578 | # | Susan Harrison | 455-4583 | Asprin | Propranolol | William Bush | 787 | # | Tom Serveas | 787-9989 | Levotyroxin | | Sara Robinson | 578 | # +----------------+--------------------+-------------+-------------+---------------+------------+ # # Each patient has only one doctor, # You may need to create multiple tables, # ########################################## ###### Question No. 2 ################################################## ########################################## # # Find all patients whose last name is 'McDonnald' # (hint: expect 2 rows) # ########################################## ###### Question No. 3 ################################################## ########################################## # # Find all patients who live in City_id 3 # (hint: expect 5 rows) # ########################################## ###### Question No. 4 ################################################## ########################################## # # Find all patients who live in 'Montreal' # (hint: expect 3 rows) # ########################################## ###### Question No. 5 ################################################## ########################################## # # Find all patients whose first name is 'John' # but their last name is NOT 'McDonnald' # (hint: expect 1 row) # ########################################## ###### Question No. 6 ################################################## ########################################## # # Find all patients whose first name starts # with the letter 'J' # (hint: expect 4 rows) # ########################################## ###### Question No. 7 ################################################## ########################################## # # Find all patients whose first name contains # the letter 'a' and their id is more than 30 # (hint: expect 9 rows) # ########################################## ###### Question No. 8 ################################################## ########################################## # # Find all patients whose first name contains # the letter 'a' and their last name starts with 'j' # (hint: expect 2 rows) # ########################################## ###### Question No. 9 ################################################## ########################################## # # Find all patients whose first name contains # the letter 'e' and their last name does NOT # contain the letter 'e' # (hint: expect 11 rows) # ########################################## ###### Question No. 10 ################################################## ########################################## # # Find all patients whose first name contains # the letter 'e' and their last name does NOT # contain the letters 'e', 'a' and 'o' # (hint: expect 1 row) # ########################################## ###### Question No. 11 ################################################## ########################################## # # Find all patients whose last name starts with # the letter 'a' and sort them based on the # last names # (hint: expect 4 rows) # ########################################## ###### Question No. 12 ################################################## ########################################## # # Find all patients who live in city_id 1 # and sort them initially based on their last # name and then based on their first name # (hint: expect 15 rows) # ########################################## ###### Question No. 13 ################################################## ########################################## # # Find all patients whose first name is one # of these names: 'John', 'Sam', 'Peter' # and are sorted based on first names # (hint: expect 6 rows) # ########################################## ###### Question No. 14 ################################################## ########################################## # # Find only the first name and last name # of the patients whose first # name contain the letter ‘j’ but their # family name does NOT include the word # ‘donnald’ # (hint: expect 3 rows) # ########################################## ###### Question No. 15 ################################################## ########################################## # # Find the first 10 patients whose city_id # is 1 or 3 while sorting them based on # their family name. # (hint: expect 10 rows!) # ########################################## ###### Question No. 16 ################################################## ########################################## # # Use the following query: # SELECT * FROM pat_info,city_info # WHERE pat_info.City_id = city_info.City_id # What do you understand from this # complex query? # ########################################## ###### Question No. 17 ################################################## ########################################## # # Can you modify the last query so it # shows the phone information from all # of the patients? # (hint: expect 49 rows!) # ##########################################