Create a view, called PatientSmithDoctors, to list all the doctors a patient with the last name of Smith has seen (be careful on this one).
SQL
SQL stands for Structured Query Language, is a form of communication that uses queries structured in a specific format to store, manage & retrieve data from a relational database.
Queries
A query is a type of computer programming language that is used to retrieve data from a database. Databases are useful in a variety of ways. They enable the retrieval of records or parts of records, as well as the performance of various calculations prior to displaying the results. A search query is one type of query that many people perform several times per day. A search query is executed every time you use a search engine to find something. When you press the Enter key, the keywords are sent to the search engine, where they are processed by an algorithm that retrieves related results from the search index. Your query's results are displayed on a search engine results page, or SER.
Question 1
Write SQL statements to answer questions 1.1, 1.2, 1.3 and 1.4 based on the following schema. Primary keys are( BOLD and italicized) and attributes with the same names in different tables are foreign keys.
Doctors(doctorId, doctorLastName, doctorFirstName,specialtyID, numberOfPatientsSeen)
Patients(patientId, patientLastName, patientFirstName, sex, patientBalance, numberOfVisits, patientDateOfBirth )
Records(doctorId, patientId, date, diagnosis, visitCost)
Specialty(specialtyId, specialtyName, specialtyCost)
1.1) Create a view, called PatientSmithDoctors, to list all the doctors a patient with the last name of Smith has seen (be careful on this one).
1.2) Write a trigger, each time a row is inserted in the table Records, the numberOfVisits in the corresponding Patient row is updated by 1 (i.e. add 1 to the numberOfVisits) and the numberOfPatientsSeen in the Doctors table is also updated by 1.
1.3) Find the Patient’s full name with the smallest balance.
1.4) For each patient, list patient identifier, patient’s full name and the total number of visits to see a doctor that the patient had.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images