SQL Exercises – Part II April 11, 2017.

Slides:



Advertisements
Similar presentations
Unit17 What Is Canadas Favorite Sport ? Paragraph 1 Canadas favorite sport Age Hockeys history.
Advertisements

Logical DB Design: ER to Relational Entity sets to tables. Employees ssn name lot CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER, PRIMARY.
 A Medical Doctor has many obligations like the examination of his/her patients, diagnosis, the prescription of medicine, minor operations and different.
Review Session Monday, Oct 8 Shipra Agrawal. Announcements New Gradiance assignment deadline Wednesday, Oct 10 Please read FAQs for assignments.
1 Relational Algebra April 13, Exercise 1 Consider the following relational database scheme: Treatment (disease, medication) Doctor(name, disease-of-specialization)
Relational Algebra and SQL Exercises
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Programming, Triggers Chapter 5 Modified by Donghui Zhang.
Building Episodes of Care Gregory H. Partridge Focused Medical Analytics PAI Seminar – Understanding Episodes of Care Chicago, June 22, 2007.
Somaiya Medical College and Maina Foundation Five Year Project for Raising breast Cancer Awareness in Pratikshanagar - Mumbai.
The Personal Planner can be used to find out information about a student in your VTT.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts - 6 th Edition SQL Schema Changes and table updates instructor teaches.
Place of Employment: Seattle Children’s Research Hospital Type of Work: Diagnosis and treatment of epilepsy, neurogenetic disorders, and neurometabolic.
Hospital Management System (Requirement). Requirement 1.Admissions 2.Doctor Appointments 3.Tests Appointments 4.Bed Allotment 5.Undergo Operation 6.Login.
INTRODUCTION TO ICD-9-CM
Click to go to salary Work environment Education or training This picture is the home button just click on it when you want to go back to this page. Hello.
By : Lynnette Gerandy Sanchez. M. Veterinarians provide healthcare treatment to animals, just as medical doctors do to human beings. Primarily, veterinarians.
Ridgeview Medical School Med Student Orientation.
Oxford Medicine Online
Football in Slovenia and in the Netherlands By: Jus, David and Joep jusdavid123.blog.com Our question: In which country is football being played at a higher.
1 Good Questions for Good Health. 2 Health Information Can Be Confusing Everyone wants help with health information You are not alone if you find health.
BY: KIROLOS-FADY SAEED RN & ARNP. RN 2 & 4 Year degree (AA or BSN) largest employment--2.5 million jobs.
Registered Nurse (RN) Alex Foust. About An RN can give medication, give shots, write notes, talk to patients, prepare for procedures, monitor patients.
10/24/2015Clinic Management System (ALO Team) Clinic Management System 1.
DOCTORS. MEDICAL DOCTOR (MD) - SPECIALIST COMPLETED HIGHER MEDICAL EDUCATION, WHICH IS PROFESSIONALLY ENGAGED IN SUPPORTING OR RESTORING HUMAN HEALTH.
Cardiology By: Julia Moore. The Heart & It’s Parts.
E-R model for Exercise #1 Comments: 1. There is a lot of process, or data flow information in this description that will not be modeled in the E-R diagram,
Physical therapist Physical therapists treat patients who have disabilities because of disease, injury, or loss of a body part by using exercise, light,
TO BE A CLINICAL PSYCHOLOGIST… WHAT IS IT?  Someone who focuses on diagnosing and treating mental illnesses.
Registered Nurses Scientific English 331 Faculty of Nursing School of Nursing 2011 Second Semester.
1Database Management Systems Exercise II  Consider the following relational schemas:  employee (person_name, street, city)  company (company_name, city)
Matsievskaya Larissa Leonardovna Karaganda 2014 Karaganda State Medical University Department foundations of psychology and communicative skills.
Allied health professionals make up 60 percent of the total health workforce. They work in health care teams to make the healthcare system function by.
Sid the Kid in action! Sidney Crosby.
Maj. Gen. Mohammad A. Aldayel, MD MBBS, MSc, ABFM Monday 05 October,2015.
Josephs top ten favorite things.. My favorite school subject. Reading Reading is fun The teacher gives gum We learn reading strategies.
What Is The Most Important Statistic In The NHL? Does a higher Corsi%, Save %, or Shot % increase your chances of winning a Stanley Cup?
Pediatrician One on One. What Is A Pediatrician? A pediatrician is someone who examine patients, order, perform and interprets diagnostic tests, and examine.
PAPER VS. PRESENTATION Case Study Guidelines. Essential Components of A Case Study Objective Pertinent Anatomical Structures Case Background Information.
Employment Outlook – Employment of athletic trainers is projected to grow 37 percent from 2008 to It is expected to grow so much because of the.
SQL - DML Review with an example. 2 SELECT Statement SELECT [DISTINCT | ALL] {* | [columnExpression [AS newName]] [,...] } FROMTableName [alias] [,...]
MONDAY 01/02/2016 Professional English in Use, Medicine Medical Practitioners 1.
1 Relational Algebra & SQL Query Formulation Exercise.
Dr.Roba AL-agha. Definition : The act of sending someone to another person or place for treatment, help, advice, etc. A referral is usually necessary.
Unit 1.1 Review MI.
Avanti Dental Care – A Reputed Alpharetta Oral Health Center.
What is Medical Tourism?
By : Miguel Gutierrez Ideal Job.
Pain Management Doctor San Antonio | Spine Care in San Antonio Texas
5 Ways Telemedicine is Revolutionizing Healthcare in Rural Areas.
Feel Better With The Treatment of Dr. Shapiro!
Foremost and Leading Ear Nose & Throat Doctor BaysideEar Nose & Throat Doctor Bayside
SQL : Query Language Part II CS3431.
More Than Treatment.
Backed by Established Clinical Guidelines
Medical Second Opinion In Action: Spinal Surgery
“ ” Problem: Following a lengthy hospital stay, better control
Double Your Money.
OncoLife-PMMNG partnership: Improving survivorship care plans for chronic cancer survivors Joseph Benci March 10, 2018.
Get out a sheet of paper. You each have been given a sheet of paper titled “Disease Diagnosis” Determine as a group, using notes from yesterday, what each.
Breast Cancer FIGHT BREAST CANCER AT THE SMARTEST WAY.
Patient charts By: Doctor (YOUR NAME!!!).
Database Quizz I Write down your answers in word document with file name highlighting your name, student number, and class. E.g “95002”+”_”+ “03 class”+”_”+”name”,
TELEMEDICINE PROJECT IN MONTENEGRO
Workshop Exercise (Week 6)
Blood donation Did you know that every day, new medical treatments are being developed and more operations are being carried out? Not surprisingly, blood.
Care Plan For Treatment plan
Workshop Exercise (Week 6)
5th edition NTP MANUAL OF PROCEDURES Case Finding
THE RIGHTS Right to emergency medical care
Full Body MRI Rockville
Presentation transcript:

SQL Exercises – Part II April 11, 2017

Exercise 1 Consider the following relational database scheme: Treatment (disease, medication) Doctor(name, disease-of-specialization) Treated (doctor_name, patient_name, date, procedure, diagnostic) Patients and doctors are uniquely identified by their name A patient may suffer from several diseases, and may take several medications for each disease. It is possible to a doctor to be a patient and vice-versa. The domains of the attributes "disease" and "disease-of-specialization" are the same, namely, the set of all diseases. In "treated" relation, the procedure could be consultation, or intervention (surgery etc.) and the diagnostic could be the name of a disease or the type of intervention. Write the following queries in SQL:

Exercise 1 (a) Treatment (disease, medication) Doctor (name, disease-of-specialization) Treated (doctor_name, patient_name, date, procedure, diagnostic) Give the name of doctors who don't suffer from any disease.

Solution 1 (a) – Method 1 Give the name of doctors who don't suffer from any disease. DoctorsWhoSuffered(name (name=patient_name (Doctor  Treated))) name (Doctor) – DoctorsWhoSuffered In SQL: SELECT distinct name FROM Doctor EXCEPT SELECT name FROM Doctor, Treated WHERE name = patient_name

Solution 1 (a) – Method 2 Give the name of doctors who don't suffer from any disease. SELECT distinct d.name FROM DOCTOR d WHERE NOT EXISTS (SELECT * FROM TREATED t WHERE d.name = t.patient_name);

Exercise 1 (b) Treatment (disease, medication) Doctor (name, disease-of-specialization) Treated (doctor_name, patient_name, date, procedure, diagnostic) List patients who suffer from more than one disease.

Solution 1 (b) List patients who suffer from more than one disease. Patient1(name1, diagnostic1) (patient_name, diagnostic ( Treated)) Patient2(name2, diagnostic2) (Patient1) name1 (name1=name2 AND diagnostic1 <> diagnostic2 (Patient1  Patient2)) In SQL: SELECT distinct p1.patient_name FROM TREATED p1, TREATED p2 WHERE p1.patient_name = p2.patient_name AND p1.diagnostic <> p2.diagnostic;

Exercise 1 (c) Treatment (disease, medication) Doctor (name, disease-of-specialization) Treated (doctor_name, patient_name, date, procedure, diagnostic) Give the names of doctors who are also patients suffering from a disease in their own specialization.

Solution 1 (c) Give the names of doctors who are also patients suffering from a disease in their own specialization. name (name=patient_name AND disease-of-specialty = diagnostic (Doctor  Treated)) In SQL: SELECT distinct name FROM DOCTOR, TREADTED WHERE name = patient_name AND disease-of-specialization = diagnostic;

Exercise 1 (d) Treatment (disease, medication) Doctor (name, disease-of-specialization) Treated (doctor_name, patient_name, date, procedure, diagnostic) Find diseases for which there is only one medication.

Solution 1 (d) – Method 1 Find diseases for which there is only one medication. DiseaseWithMoreThanOneTreatment (t1.disease (t1.disease=t2.disease AND t1.medication <> t2.medication (t1(Treatment)  t2(Treatment)) disease (Treatment) – DiseaseWithMoreThanOneTreatment In SQL: SELECT distinct disease FROM Treatment EXCEPT SELECT t1.disease FROM Treatment t1, Treatment t2 WHERE t1.disease =t2.disease AND t1.medication <> t2.medication

Solution 1 (d) – Method 2 Find diseases for which there is only one medication. SELECT distinct t1.disease FROM TREATMENT t1 WHERE NOT EXISTS (SELECT t2.disease FROM TREATMENT t2 WHERE t1.disease = t2.disease AND t1.medication <> t2.medication);

Exercise 1 (e) Treatment (disease, medication) Doctor (name, disease-of-specialization) Treated (doctor_name, patient_name, date, procedure, diagnostic) Find the names of patient who had an operation done by a doctor with HIV

Solution 1 (e) Find the names of patient who had an operation done by a doctor with HIV. SELECT distinct t1.patient_name FROM TREATED t1 WHERE (t1.procedure=“intervention” AND t1.doctor_name IN ( SELECT distinct d1.name FROM TREATED t2, DOCTOR d1 WHERE (t2.patient_name=d1.name AND t2.diagnostic=“HIV”)));

Exercise 1 (f) Treatment (disease, medication) Doctor (name, disease-of-specialization) Treated (doctor_name, patient_name, date, procedure, diagnostic) List the patients who consulted 2 or more doctors and was given exactly the same diagnosis. List patient’s name, doctor’s name, the date, and the diagnosis.

Solution 1 (f) List the patients who consulted 2 or more doctors and was given exactly the same diagnosis. List patient’s name, doctor’s name, the date, and the diagnosis. SELECT distinct t1.patient_name, t1.doctor_name, t1.date, t1.diagnostic FROM TREATED t1, TREATED t2 WHERE t1.patient_name = t2.patient_name AND t1.doctor_name <> t2.doctor_name AND t1.diagnostic=t2.diagnostic

Exercise 2 Consider the following relation scheme about hockey teams: Team (tname, year, coach, salary) Player (pname, position) Winner (tname, year) Played (pname, tname, year, salary) Assume that players and coaches appointments with teams are on a calendar year basis. The team relation indicates teams, their coaches on yearly basis and their salaries. The player relation indicates players and the position each player plays. The winner relation indicates the Stanley Cup winners. The played relation indicates players and the team they have played for on a yearly basis. Write the following queries in SQL:

Exercise 2 (a) Team (tname, year, coach, salary) Player (pname, position) Winner (tname, year) Played (pname, tname, year, salary) List all the players who have salary higher than 2M$, and have played for all the teams in the league

Solution 2 (a) List all the players who have salary higher than 2M$, and have played for all the teams in the league SELECT p1.pname FROM PLAYED p1 WHERE p1.salary > 20000000 Group by p1.pname Having count (distinct p1.tname) = (Select count (distinct team.tname) From TEAM);

Exercise 2 (b) Team (tname, year, coach, salary) Player (pname, position) Winner (tname, year) Played (pname, tname, year, salary) List coaches who have also been players, and have coached only teams they once played for.

Solution 2 (b) List coaches who have also been players, and have coached only teams they once played for. SELECT distinct t1.coach FROM TEAM t1 EXCEPT WHERE t1.coach NOT IN (SELECT p1.pname FROM PLAYED p1 WHERE p1.tname=t1.tname);

Exercise 2 (c) Team (tname, year, coach, salary) Player (pname, position) Winner (tname, year) Played (pname, tname, year, salary) List all the players who won the Stanley Cup during two consecutive years with two different teams.

Solution 2 (c) List all the players who won the Stanley Cup during two consecutive years with two different teams. SELECT distinct a1.pname FROM(SELECT p.pname, p.tname, p.year FROM PLAYED p, WINNER w WHERE p.tname = w.tname AND p.year=w.year;) a1, (SELECT p.pname, p.tname, p.year WHERE p.tname = w.tname AND p.year=w.year;) a2 WHERE a1.pname = a2.pname AND a1.tname <> a2.tname AND (a1.year = a2.year – 1 OR a1.year = a2.year + 1);

Exercise 2 (d) Team (tname, year, coach, salary) Player (pname, position) Winner (tname, year) Played (pname, tname, year, salary) List all coaches who earn more than the highest player's salary in the team.

Solution 2 (d) List all coaches who earn more than the highest player's salary in the team. Select coach From Team Where salary > All (Select salary From Played Where Team.tname=Played.tname)