Академический Документы
Профессиональный Документы
Культура Документы
Given the following tables, please generate the SQL syntax to provide the requested functions and/or reports
Doctor
ID number(4) primary key
name varchar2(20) /* Last,First */
Disease
code char(3) primary key
name varchar2(20)
contagion number(1) /* 0=none, 5=highest */
Expertise
exp_key number(5) primary key /* sequence # */
doctor number(4) references doctor(ID)
disease char(3) references disease(code),
Patient
ID number(5) primary key
name varchar2(20) /* Last,First */
doctor number(4) references doctor(ID)
room char(3) /* 1st character is floor */
disease char(3) references disease(code)
med_ins varchar2(10) /* Name of carrier */
bill_amt number(9,2)
admit_dt date
release_dt date /* null until patient is released */
select p.*
from patient p, disease d
where p.dis_code = d.dis_code and d.contagion > 2
3. How many patients were in the hospital 2 weeks ago today? Subtotal by floor. (Note: “Floor” is the 1st
character of the room number).
no data found
4. Select all current patients that have contagion “5” diseases and all doctors that treat contagion “5” diseases.
Ensure you note whether it is a doctor or patient and sort them by name.
select 'doctor' "TYPE", d.name
from doctor d, expertise e, disease dis
where d.ID = e.ID and e.disease = dis.dis_code AND dis.contagion = 5
UNION
select 'patient', p.name
from patient p join disease dd on p.dis_code = dd.dis_code
where dd.contagion = 5
TYPE NAME
doctor Hunnicut,Mike
doctor Welby.Marcus
doctor Zorba,John
patient Armstrong,John
patient Earheart,Peter
patient Masters,Rose
patient Peterson,John
patient Rawlins,Eileen
patient Talbot,Fred
5. Which disease names end in “itis” and note how contagious they are?
select d.name
from disease d
where d.name like '%itis'
NAME
Hepatitis
6. For each insurance provider, what is the average duration of stay? Round the result to full days.
Harvard 23.9
United 28.7
BCBS 11.2
Medicare 29.2
7. Select all patient last names and first initials, with a comma (e.g. “Smith,J”), and note what day of the week
they were admitted.
select substr(name,1,instr(name,',')+1) "Name", to_char(admit_dt, 'Day') "Admitted Day of
Week"
from patient
Armstrong,J Friday
Baker,A Monday
Chalice,M Saturday
Driver,M Saturday
Earheart,P Wednesday
Falcon,M Friday
Garrison,J Tuesday
Hampton,K Friday
Infante,M Friday
Johnson,G Tuesday
MINUS
select p.dis_code
from patient p
no data found