SlideShare a Scribd company logo
SQL Project 1
1. Display the contents of the DOCTOR, PATIENT, and BILLING tables.
2. Display each patient’s first name, last name, and date of birth, using “First Name”, “Last Name”, and
“Birth Date” instead of the default ones. Note: Use column aliases.
3. For each doctor, display his or her name and annual income, using “Annual Income” as the column
alias. Note: Annual income = 12*(Salary per month) + Annual bonus. What’s the problem with your
result? Why is it? How to handle this problem? Hint: Use NVL.
4. Display each patient’s name and date of birth in sentence form under heading of “Patient
Information”. One example is “Paul James was born on 14-MAR-97.” Note: Use the concatenation
operator (||) to join two character strings.
5. Display the current date. Note: Use a dummy table named DUAL.
6. Determine the number of days that have elapsed since each patient’s last visit, using “Days Since
Last Visit” as the column alias.
7. Display the IDs of all doctors assigned to patients. Modify the previous example to eliminate display
of duplicate values by using DISCTINCT.
8. Display all doctor’s names and hire dates in chronological order with the person on staff the longest
listed first. Modify the previous example to begin the list with the person on staff for the shortest
time.
9. For each patient, display the patient ID and the number of days since their last appointment in order
with the most recently seen patient listed first, using “Days Since Appt” as the column alias.
10. Display the names of doctors who change at least $40 per appointment.
11. Display the names of patients whose next appointment is less than 60 days since their last
appointment.
12. Display all data on patients whose last name is James. Note: Make sure to match the case of literal
string in WHERE clause with the case used in the table.
13. Display the IDs and balances of patients that owe at least $300 and no more than $500. Note: Use
the BETWEEN operator.
14. Display the names and areas of doctors specializing in pediatrics or family practice. Note: Using the
IN operator.
15. Display the IDs of doctors that do not receive annual bonuses. Note: Use the IS NULL operator.
16. Display all billing data for patients living on N. Allen Street. Note: Use the LIKE operator. The LIKE
operator is used in conjunction with wildcard characters (% or _) to match character string patterns.
17. Display the IDs, balances, and due dates for patients that have balances over $10,000.
18. Display all billing data on patients who either have balances of more than $90,000 or have insurance
with SIH.
19. Display all data on patients except those with a last name of James, Jones, Wright, or Walters. Note:
Use NOT IN.
20. Display all data on patients whose full name matches that entered by the user. Try “Brian
Anderson”. Note: Use ACCEPT.
SCRIPTS AND STATEMENTS
1.
select * from doctor;
select * from patient;
select * from billing;
2.
select pt_fname "First Name", pt_lname "Last Name", ptdob "Birth Date"
from patient;
3.
select DOC_NAME "DOCTOR",
((SALPERMON *12) + NVL (ANNUAL_BONUS,0)) "ANNUAL INCOME"
from DOCTOR
4.
SELECT PT_FNAME||' '||PT_LNAME||' '||'was born on'||' '||PTDOB
"PATIENT INFORMATION"
FROM PATIENT
5.
SELECT TO_CHAR
(SYSDATE, 'MM-DD-YYYY') "NOW"
FROM DUAL;
6.
select 'It has been'||' '|| ROUND(SYSDATE - LASTAPPTD,0)||','||'days since'||' '||
PT_FNAME||' '||PT_LNAME||' '|| 'last visit.' "Days Since Appt"
FROM PATIENT
7.
select distinct doc_id "DOCs w/ PTs by: DOC ID"
from patient;
select doc_id "*Same* But Has Duplicates"
from patient;
8.
select doc_name, datehired
from doctor
order by datehired;
select doc_name, datehired
from doctor
order by datehired desc;
9.
select PT_ID ||'-'||PT_FNAME||' '||PT_LNAME||' '||
ROUND(SYSDATE - LASTAPPTD,0)||','||' days since last appt.' "Days Since Appt"
FROM PATIENT
order by LASTAPPTD desc;
10.
SELECT DOC_NAME"DOCTOR",CHGPERAPPT"CHARGE PER APPT LESS $40"
From DOCTOR
WHERE CHGPERAPPT >= 40
order by CHGPERAPPT;
11.
SELECT PT_FNAME||' '||PT_LNAME "Name",
(NEXTAPPTD-LASTAPPTD)"Days Until Next Appt"
from PATIENT
WHERE(NEXTAPPTD-LASTAPPTD) < 60
order by "Days Until Next Appt";
12.
SELECT * FROM PATIENT
WHERE PT_LNAME = 'James';
13.
SELECT PT_ID,BALANCE
From BILLING
WHERE BALANCE between 300 and 500;
14.
select DOC_NAME,DOC_ID,AREA
from doctor
where AREA IN ('Pediatrics','Family Practice');
15.
select DOC_ID,DOC_NAME,ANNUAL_BONUS
FROM DOCTOR
Where ANNUAL_BONUS IS NULL
16.
SELECT * FROM billing
WHERE ADDR LIKE '% N. Allen';
17.
select PT_ID,BALANCE,DUEDATE
from billing
where BALANCE > 10000;
18.
select * from BILLING
where PT_INS LIKE '%SIH' or balance > 90000;
19.
select * from PATIENT
where PT_LNAME NOT IN ('james','jones','wright','walter');
20.
accept last_name prompt 'What is the patient''s last name?'
accept first_name prompt 'And the patient''s first name?'
select * from patient
where pt_lname = '&last_name' and pt_fname = '&first_name';
OUTPUTS of SCRIPTS AND STATEMENTS
1.
DOC_ID DOC_NAME DATEHIRED SALPERMON AREA SUPERVISOR_ID CHGPERAPPT
ANNUAL_BONUS
---------- -------------------- --------- ---------- -------------------- ------------- ---------- ------------
432 Harrison 05-DEC-94 12000 Pediatrics 100 75 4500
509 Vester 09-JAN-02 8100 Pediatrics 432 40
389 Lewis 21-JAN-96 10000 Pediatrics 432 40 2250
504 Cotner 16-JUN-98 11500 Neurology 289 85 7500
235 Smith 22-JUN-98 4550 Family Practice 100 25 2250
356 James 01-AUG-98 7950 Neurology 289 80 6500
558 James 02-MAY-95 9800 Orthopedics 876 85 7700
876 Robertson 02-MAR-95 10500 Orthopedics 100 90 8900
889 Thompson 18-MAR-97 6500 Rehab 100 65 3200
239 Pronger 18-DEC-99 3500 Rehab 889 40
289 Borque 30-JUN-89 16500 Neurology 100 95 6500
100 Stevenson 30-JUN-79 23500 Director
12 rows selected
2.
PT_ID PT_LNAME PT_FNAME PTDOB DOC_ID NEXTAPPTD LASTAPPTD
---------- -------------------- -------------------- --------- ---------- --------- ---------
168 James Paul 14-MAR-97 432 01-JUL-03 01-JUN-03
331 Anderson Brian 31-MAR-48 235 01-JUL-03 01-JUN-03
313 James Scott 26-MAR-33 235 20-JUL-03 20-JUN-03
816 Smith Jason 12-DEC-99 509 15-NOV-03 15-MAY-03
314 Porter Susan 14-NOV-67 235 01-OCT-03 01-MAR-03
315 Saillez Debbie 09-SEP-55 235 01-JUL-03 01-JUN-03
719 Rogers Anthony 01-JAN-42 504 01-NOV-03 01-JAN-03
264 Walters Stephanie 26-JAN-45 504 12-DEC-03 12-DEC-02
267 Westra Lynn 12-JUL-57 235 02-FEB-04 02-FEB-03
103 Poole Jennifer 13-MAY-02 389 01-DEC-03 01-JUN-03
108 Baily Ryan 25-DEC-77 235 06-JUN-05 06-JUN-03
943 Crow Lewis 10-NOV-49 235 01-JUL-05 01-MAR-02
847 Cochran John 28-MAR-48 356 02-DEC-05 01-JAN-02
163 Roach Becky 08-SEP-75 235 01-DEC-05 01-JAN-02
504 Jackson John 08-NOV-43 235 21-JUL-03 10-NOV-02
809 Kowalczyk Paul 12-NOV-51 558 29-JUL-03 19-JUN-03
703 Davis Linda 17-JUL-02 509 21-JUL-03 22-MAY-03
307 Jones J.C. 17-JUL-02 509 21-JUL-03 22-MAY-03
439 Wright Chasity 23-APR-73 235
696 Vanderchuck Keith 08-AUG-68 504 15-JUN-03
966 Mcginnis Allen 03-MAY-59 504 15-JUN-03
669 Sakic Joe 16-SEP-76 504 15-JUN-03
22 rows selected
3.
PT_ID BALANCE DUEDATE PHONE ADDR CITY ST ZIP PT_INS
-------------------- ---------- --------- ---------- ------------------------------ -------------------- -- ----- --------------------
168 15650 21-AUG-03 833-9569 128 W. APPLE #4 Jonesboro IL 62952 SIH
331 300 09-SEP-03 833-5587 3434 Mulberry St. Anna IL 62906 BCBS
313 0 01-JAN-04 893-9987 334 Tailgate Ln COBDEN IL 62920 Military
816 0 01-JAN-04 833-6654 8814 W. Apple JONESBORO IL 62952 SIH
314 100 31-MAR-03 457-6658 445 Oak St. Carbondale IL 62901 BCBS
264 35000 11-JAN-03 942-8065 8898 Bighill Driver HERRIN IL 62948
MediSupplA
103 4500 01-JUL-03 833-5547 298 Murphy School Rd Anna IL 62906
HealthCare
108 0 01-JAN-05 833-5542 334 Pansie Hill Rd. JONESBORO IL 62952
HealthCare
943 0 01-JAN-07 529-9963 456 E. Grand #14 Carbondale IL 62901 Military
847 98000 31-JAN-02 549-8854 6543 W. Parkview Ln. Carbondale IL 62901 BCBS
504 0 01-JAN-03 549-6139 6657 N. Allen Carbondale IL 62901 QualityCare
809 450 19-JUL-03 687-8852 3345 Hwy 127 N. Murphysboro IL 62966
QualityCare
703 225 31-AUG-03 529-8332 909 N. Brown St. Carbondale IL 62901
HealthCare
696 79850 15-JUL-03 549-7231 5546 W. James Carbondale IL 62901 BCBS
966 98700 15-JUL-03 833-5375 9009 Taylor Ave. Anna IL 62906 BCBS
267 0 01-JAN-05 942-3321 6755 US Route 148 HERRIN IL 62948
QualityCare
307 450 31-AUG-03 457-6967 234 N. Allen Carbondale IL 62901
HealthCare
719 0 01-JAN-04 549-7848 867 Henderson St. Carbondale IL 62901
HealthCare
439 500 31-AUG-03 833-5541 4456 N. Springer Anna IL 62906
QualityCare
315 1500 14-SEP-03 833-6272 404 Williford Rd. JONESBORO IL 62952
HealthCare
163 0 01-JAN-04 833-2133 129 Fountain St. Anna IL 62906 HealthCare
669 128450 15-JUL-03 833-6654 353 Tin Bender Rd. Jonesboro IL 62952 BCBS
22 rows selected
4.
First Name Last Name Birth Date
-------------------- -------------------- ----------
Paul James 14-MAR-97
Brian Anderson 31-MAR-48
Scott James 26-MAR-33
Jason Smith 12-DEC-99
Susan Porter 14-NOV-67
Debbie Saillez 09-SEP-55
Anthony Rogers 01-JAN-42
Stephanie Walters 26-JAN-45
Lynn Westra 12-JUL-57
Jennifer Poole 13-MAY-02
Ryan Baily 25-DEC-77
Lewis Crow 10-NOV-49
John Cochran 28-MAR-48
Becky Roach 08-SEP-75
John Jackson 08-NOV-43
Paul Kowalczyk 12-NOV-51
Linda Davis 17-JUL-02
J.C. Jones 17-JUL-02
Chasity Wright 23-APR-73
Keith Vanderchuck 08-AUG-68
Allen Mcginnis 03-MAY-59
Joe Sakic 16-SEP-76
22 rows selected
5.
NOW
----------
05-06-2014
6.
Days Since Appt ----------------
It has been 3992,days since Paul James last visit.
It has been 3992,days since Brian Anderson last visit.
It has been 3973,days since Scott James last visit.
It has been 4009,days since Jason Smith last visit.
It has been 4084,days since Susan Porter last visit.
It has been 3992,days since Debbie Saillez last visit.
It has been 4143,days since Anthony Rogers last visit.
It has been 4163,days since Stephanie Walters last visit.
It has been 4111,days since Lynn Westra last visit.
It has been 3992,days since Jennifer Poole last visit.
It has been 3987,days since Ryan Baily last visit.
It has been 4449,days since Lewis Crow last visit.
It has been 4508,days since John Cochran last visit.
It has been 4508,days since Becky Roach last visit.
It has been 4195,days since John Jackson last visit.
It has been 3974,days since Paul Kowalczyk last visit.
It has been 4002,days since Linda Davis last visit.
It has been 4002,days since J.C. Jones last visit.
It has been ,days since Chasity Wright last visit.
It has been 3978,days since Keith Vanderchuck last visit.
It has been 3978,days since Allen Mcginnis last visit.
It has been 3978,days since Joe Sakic last visit.
22 rows selected
7.
DOCs w/ PTs by: DOC ID
----------------------
432
504
389
558
235
509
356
7 rows selected
*Same* But Has Duplicates
-------------------------
432
235
235
509
235
235
504
504
235
389
235
235
356
235
235
558
509
509
235
504
504
504
22 rows selected
8.
DOC_NAME DATEHIRED
-------------------- ---------
Stevenson 30-JUN-79
Borque 30-JUN-89
Harrison 05-DEC-94
Robertson 02-MAR-95
James 02-MAY-95
Lewis 21-JAN-96
Thompson 18-MAR-97
Cotner 16-JUN-98
Smith 22-JUN-98
James 01-AUG-98
Pronger 18-DEC-99
Vester 09-JAN-02
12 rows selected
DOC_NAME DATEHIRED
-------------------- ---------
Vester 09-JAN-02
Pronger 18-DEC-99
James 01-AUG-98
Smith 22-JUN-98
Cotner 16-JUN-98
Thompson 18-MAR-97
Lewis 21-JAN-96
James 02-MAY-95
Robertson 02-MAR-95
Harrison 05-DEC-94
Borque 30-JUN-89
Stevenson 30-JUN-79
12 rows selected
9.
Days Since Appt --------------
439-Chasity Wright , days since last appt.
313-Scott James 3973, days since last appt.
809-Paul Kowalczyk 3974, days since last appt.
966-Allen Mcginnis 3978, days since last appt.
696-Keith Vanderchuck 3978, days since last appt.
669-Joe Sakic 3978, days since last appt.
108-Ryan Baily 3987, days since last appt.
168-Paul James 3992, days since last appt.
331-Brian Anderson 3992, days since last appt.
103-Jennifer Poole 3992, days since last appt.
315-Debbie Saillez 3992, days since last appt.
307-J.C. Jones 4002, days since last appt.
703-Linda Davis 4002, days since last appt.
816-Jason Smith 4009, days since last appt.
314-Susan Porter 4084, days since last appt.
267-Lynn Westra 4111, days since last appt.
719-Anthony Rogers 4143, days since last appt.
264-Stephanie Walters 4163, days since last appt.
504-John Jackson 4195, days since last appt.
943-Lewis Crow 4449, days since last appt.
163-Becky Roach 4508, days since last appt.
847-John Cochran 4508, days since last appt.
22 rows selected
10.
DOCTOR CHARGE PER APPT LESS $40
-------------------- ------------------------
Vester 40
Lewis 40
Pronger 40
Thompson 65
Harrison 75
James 80
Cotner 85
James 85
Robertson 90
Borque 95
10 rows selected
11.
Name Days Until Next Appt
----------------------------------------- --------------------
Paul James 30
Brian Anderson 30
Scott James 30
Debbie Saillez 30
Paul Kowalczyk 40
12.
PT_ID PT_LNAME PT_FNAME PTDOB DOC_ID NEXTAPPTD LASTAPPTD
---------- -------------------- -------------------- --------- ---------- --------- ---------
168 James Paul 14-MAR-97 432 01-JUL-03 01-JUN-03
313 James Scott 26-MAR-33 235 20-JUL-03 20-JUN-03
13.
PT_ID BALANCE
-------------------- ----------
331 300
809 450
307 450
439 500
14.
DOC_NAME DOC_ID AREA
-------------------- ---------- --------------------
Harrison 432 Pediatrics
Vester 509 Pediatrics
Lewis 389 Pediatrics
Smith 235 Family Practice
15.
DOC_ID DOC_NAME ANNUAL_BONUS
---------- -------------------- ------------
509 Vester
239 Pronger
100 Stevenson
16.
PT_ID BALANCE DUEDATE PHONE ADDR CITY ST ZIP PT_INS
-------------------- ---------- --------- ---------- ------------------------------ -------------------- -- ----- --------------------
504 0 01-JAN-03 549-6139 6657 N. Allen Carbondale IL 62901 QualityCare
307 450 31-AUG-03 457-6967 234 N. Allen Carbondale IL 62901
HealthCare
17.
PT_ID BALANCE DUEDATE
-------------------- ---------- ---------
168 15650 21-AUG-03
264 35000 11-JAN-03
847 98000 31-JAN-02
696 79850 15-JUL-03
966 98700 15-JUL-03
669 128450 15-JUL-03
6 rows selected
18.
PT_ID BALANCE DUEDATE PHONE ADDR CITY ST ZIP PT_INS
-------------------- ---------- --------- ---------- ------------------------------ -------------------- -- ----- --------------------
168 15650 21-AUG-03 833-9569 128 W. APPLE #4 Jonesboro IL 62952 SIH
816 0 01-JAN-04 833-6654 8814 W. Apple JONESBORO IL 62952 SIH
847 98000 31-JAN-02 549-8854 6543 W. Parkview Ln. Carbondale IL 62901 BCBS
966 98700 15-JUL-03 833-5375 9009 Taylor Ave. Anna IL 62906 BCBS
669 128450 15-JUL-03 833-6654 353 Tin Bender Rd. Jonesboro IL 62952 BCBS
19.
PT_ID PT_LNAME PT_FNAME PTDOB DOC_ID NEXTAPPTD LASTAPPTD
---------- -------------------- -------------------- --------- ---------- --------- ---------
168 James Paul 14-MAR-97 432 01-JUL-03 01-JUN-03
331 Anderson Brian 31-MAR-48 235 01-JUL-03 01-JUN-03
313 James Scott 26-MAR-33 235 20-JUL-03 20-JUN-03
816 Smith Jason 12-DEC-99 509 15-NOV-03 15-MAY-03
314 Porter Susan 14-NOV-67 235 01-OCT-03 01-MAR-03
315 Saillez Debbie 09-SEP-55 235 01-JUL-03 01-JUN-03
719 Rogers Anthony 01-JAN-42 504 01-NOV-03 01-JAN-03
264 Walters Stephanie 26-JAN-45 504 12-DEC-03 12-DEC-02
267 Westra Lynn 12-JUL-57 235 02-FEB-04 02-FEB-03
103 Poole Jennifer 13-MAY-02 389 01-DEC-03 01-JUN-03
108 Baily Ryan 25-DEC-77 235 06-JUN-05 06-JUN-03
943 Crow Lewis 10-NOV-49 235 01-JUL-05 01-MAR-02
847 Cochran John 28-MAR-48 356 02-DEC-05 01-JAN-02
163 Roach Becky 08-SEP-75 235 01-DEC-05 01-JAN-02
504 Jackson John 08-NOV-43 235 21-JUL-03 10-NOV-02
809 Kowalczyk Paul 12-NOV-51 558 29-JUL-03 19-JUN-03
703 Davis Linda 17-JUL-02 509 21-JUL-03 22-MAY-03
307 Jones J.C. 17-JUL-02 509 21-JUL-03 22-MAY-03
439 Wright Chasity 23-APR-73 235
696 Vanderchuck Keith 08-AUG-68 504 15-JUN-03
966 Mcginnis Allen 03-MAY-59 504 15-JUN-03
669 Sakic Joe 16-SEP-76 504 15-JUN-03
22 rows selected
20.
PT_ID PT_LNAME PT_FNAME PTDOB DOC_ID NEXTAPPTD LASTAPPTD
---------- -------------------- -------------------- --------- ---------- --------- ---------
313 James Scott 26-MAR-33 235 20-JUL-03 20-JUN-03

More Related Content

Viewers also liked

Portal admin workshop - JH
Portal admin workshop - JHPortal admin workshop - JH
Portal admin workshop - JH
Jonathan Hall
 
Le IAQ-TEK et Le VT8000
Le IAQ-TEK et Le VT8000Le IAQ-TEK et Le VT8000
Le IAQ-TEK et Le VT8000
atgagnon
 
Calendrier Fibrea 2017
Calendrier Fibrea 2017Calendrier Fibrea 2017
Calendrier Fibrea 2017
SOREA
 
情報リテラシー論02インターネット概論と歴史・長岡造形大学
情報リテラシー論02インターネット概論と歴史・長岡造形大学情報リテラシー論02インターネット概論と歴史・長岡造形大学
情報リテラシー論02インターネット概論と歴史・長岡造形大学
新潟コンサルタント横田秀珠
 
L'autobús conte
L'autobús conteL'autobús conte
L'autobús conte
08escola
 
Node.js - #5 - Process - Rodrigo Branas
Node.js - #5 - Process - Rodrigo BranasNode.js - #5 - Process - Rodrigo Branas
Node.js - #5 - Process - Rodrigo Branas
Rodrigo Branas
 
Antibi prophy / dental courses
Antibi prophy  / dental coursesAntibi prophy  / dental courses
Antibi prophy / dental courses
Indian dental academy
 
Use go channel to write a disk queue
Use go channel to write a disk queueUse go channel to write a disk queue
Use go channel to write a disk queue
Evan Lin
 

Viewers also liked (8)

Portal admin workshop - JH
Portal admin workshop - JHPortal admin workshop - JH
Portal admin workshop - JH
 
Le IAQ-TEK et Le VT8000
Le IAQ-TEK et Le VT8000Le IAQ-TEK et Le VT8000
Le IAQ-TEK et Le VT8000
 
Calendrier Fibrea 2017
Calendrier Fibrea 2017Calendrier Fibrea 2017
Calendrier Fibrea 2017
 
情報リテラシー論02インターネット概論と歴史・長岡造形大学
情報リテラシー論02インターネット概論と歴史・長岡造形大学情報リテラシー論02インターネット概論と歴史・長岡造形大学
情報リテラシー論02インターネット概論と歴史・長岡造形大学
 
L'autobús conte
L'autobús conteL'autobús conte
L'autobús conte
 
Node.js - #5 - Process - Rodrigo Branas
Node.js - #5 - Process - Rodrigo BranasNode.js - #5 - Process - Rodrigo Branas
Node.js - #5 - Process - Rodrigo Branas
 
Antibi prophy / dental courses
Antibi prophy  / dental coursesAntibi prophy  / dental courses
Antibi prophy / dental courses
 
Use go channel to write a disk queue
Use go channel to write a disk queueUse go channel to write a disk queue
Use go channel to write a disk queue
 

SQL Project 1-with_ans

  • 1. SQL Project 1 1. Display the contents of the DOCTOR, PATIENT, and BILLING tables. 2. Display each patient’s first name, last name, and date of birth, using “First Name”, “Last Name”, and “Birth Date” instead of the default ones. Note: Use column aliases. 3. For each doctor, display his or her name and annual income, using “Annual Income” as the column alias. Note: Annual income = 12*(Salary per month) + Annual bonus. What’s the problem with your result? Why is it? How to handle this problem? Hint: Use NVL. 4. Display each patient’s name and date of birth in sentence form under heading of “Patient Information”. One example is “Paul James was born on 14-MAR-97.” Note: Use the concatenation operator (||) to join two character strings. 5. Display the current date. Note: Use a dummy table named DUAL. 6. Determine the number of days that have elapsed since each patient’s last visit, using “Days Since Last Visit” as the column alias. 7. Display the IDs of all doctors assigned to patients. Modify the previous example to eliminate display of duplicate values by using DISCTINCT. 8. Display all doctor’s names and hire dates in chronological order with the person on staff the longest listed first. Modify the previous example to begin the list with the person on staff for the shortest time. 9. For each patient, display the patient ID and the number of days since their last appointment in order with the most recently seen patient listed first, using “Days Since Appt” as the column alias. 10. Display the names of doctors who change at least $40 per appointment. 11. Display the names of patients whose next appointment is less than 60 days since their last appointment. 12. Display all data on patients whose last name is James. Note: Make sure to match the case of literal string in WHERE clause with the case used in the table. 13. Display the IDs and balances of patients that owe at least $300 and no more than $500. Note: Use the BETWEEN operator. 14. Display the names and areas of doctors specializing in pediatrics or family practice. Note: Using the IN operator. 15. Display the IDs of doctors that do not receive annual bonuses. Note: Use the IS NULL operator.
  • 2. 16. Display all billing data for patients living on N. Allen Street. Note: Use the LIKE operator. The LIKE operator is used in conjunction with wildcard characters (% or _) to match character string patterns. 17. Display the IDs, balances, and due dates for patients that have balances over $10,000. 18. Display all billing data on patients who either have balances of more than $90,000 or have insurance with SIH. 19. Display all data on patients except those with a last name of James, Jones, Wright, or Walters. Note: Use NOT IN. 20. Display all data on patients whose full name matches that entered by the user. Try “Brian Anderson”. Note: Use ACCEPT. SCRIPTS AND STATEMENTS 1. select * from doctor; select * from patient; select * from billing; 2. select pt_fname "First Name", pt_lname "Last Name", ptdob "Birth Date" from patient; 3. select DOC_NAME "DOCTOR", ((SALPERMON *12) + NVL (ANNUAL_BONUS,0)) "ANNUAL INCOME" from DOCTOR 4. SELECT PT_FNAME||' '||PT_LNAME||' '||'was born on'||' '||PTDOB "PATIENT INFORMATION" FROM PATIENT 5. SELECT TO_CHAR (SYSDATE, 'MM-DD-YYYY') "NOW"
  • 3. FROM DUAL; 6. select 'It has been'||' '|| ROUND(SYSDATE - LASTAPPTD,0)||','||'days since'||' '|| PT_FNAME||' '||PT_LNAME||' '|| 'last visit.' "Days Since Appt" FROM PATIENT 7. select distinct doc_id "DOCs w/ PTs by: DOC ID" from patient; select doc_id "*Same* But Has Duplicates" from patient; 8. select doc_name, datehired from doctor order by datehired; select doc_name, datehired from doctor order by datehired desc; 9. select PT_ID ||'-'||PT_FNAME||' '||PT_LNAME||' '|| ROUND(SYSDATE - LASTAPPTD,0)||','||' days since last appt.' "Days Since Appt" FROM PATIENT order by LASTAPPTD desc; 10. SELECT DOC_NAME"DOCTOR",CHGPERAPPT"CHARGE PER APPT LESS $40" From DOCTOR WHERE CHGPERAPPT >= 40 order by CHGPERAPPT; 11.
  • 4. SELECT PT_FNAME||' '||PT_LNAME "Name", (NEXTAPPTD-LASTAPPTD)"Days Until Next Appt" from PATIENT WHERE(NEXTAPPTD-LASTAPPTD) < 60 order by "Days Until Next Appt"; 12. SELECT * FROM PATIENT WHERE PT_LNAME = 'James'; 13. SELECT PT_ID,BALANCE From BILLING WHERE BALANCE between 300 and 500; 14. select DOC_NAME,DOC_ID,AREA from doctor where AREA IN ('Pediatrics','Family Practice'); 15. select DOC_ID,DOC_NAME,ANNUAL_BONUS FROM DOCTOR Where ANNUAL_BONUS IS NULL 16. SELECT * FROM billing WHERE ADDR LIKE '% N. Allen'; 17. select PT_ID,BALANCE,DUEDATE from billing where BALANCE > 10000; 18. select * from BILLING where PT_INS LIKE '%SIH' or balance > 90000; 19. select * from PATIENT where PT_LNAME NOT IN ('james','jones','wright','walter');
  • 5. 20. accept last_name prompt 'What is the patient''s last name?' accept first_name prompt 'And the patient''s first name?' select * from patient where pt_lname = '&last_name' and pt_fname = '&first_name'; OUTPUTS of SCRIPTS AND STATEMENTS 1. DOC_ID DOC_NAME DATEHIRED SALPERMON AREA SUPERVISOR_ID CHGPERAPPT ANNUAL_BONUS ---------- -------------------- --------- ---------- -------------------- ------------- ---------- ------------ 432 Harrison 05-DEC-94 12000 Pediatrics 100 75 4500 509 Vester 09-JAN-02 8100 Pediatrics 432 40 389 Lewis 21-JAN-96 10000 Pediatrics 432 40 2250 504 Cotner 16-JUN-98 11500 Neurology 289 85 7500 235 Smith 22-JUN-98 4550 Family Practice 100 25 2250 356 James 01-AUG-98 7950 Neurology 289 80 6500 558 James 02-MAY-95 9800 Orthopedics 876 85 7700 876 Robertson 02-MAR-95 10500 Orthopedics 100 90 8900 889 Thompson 18-MAR-97 6500 Rehab 100 65 3200 239 Pronger 18-DEC-99 3500 Rehab 889 40 289 Borque 30-JUN-89 16500 Neurology 100 95 6500 100 Stevenson 30-JUN-79 23500 Director
  • 6. 12 rows selected 2. PT_ID PT_LNAME PT_FNAME PTDOB DOC_ID NEXTAPPTD LASTAPPTD ---------- -------------------- -------------------- --------- ---------- --------- --------- 168 James Paul 14-MAR-97 432 01-JUL-03 01-JUN-03 331 Anderson Brian 31-MAR-48 235 01-JUL-03 01-JUN-03 313 James Scott 26-MAR-33 235 20-JUL-03 20-JUN-03 816 Smith Jason 12-DEC-99 509 15-NOV-03 15-MAY-03 314 Porter Susan 14-NOV-67 235 01-OCT-03 01-MAR-03 315 Saillez Debbie 09-SEP-55 235 01-JUL-03 01-JUN-03 719 Rogers Anthony 01-JAN-42 504 01-NOV-03 01-JAN-03 264 Walters Stephanie 26-JAN-45 504 12-DEC-03 12-DEC-02 267 Westra Lynn 12-JUL-57 235 02-FEB-04 02-FEB-03 103 Poole Jennifer 13-MAY-02 389 01-DEC-03 01-JUN-03 108 Baily Ryan 25-DEC-77 235 06-JUN-05 06-JUN-03 943 Crow Lewis 10-NOV-49 235 01-JUL-05 01-MAR-02 847 Cochran John 28-MAR-48 356 02-DEC-05 01-JAN-02 163 Roach Becky 08-SEP-75 235 01-DEC-05 01-JAN-02 504 Jackson John 08-NOV-43 235 21-JUL-03 10-NOV-02 809 Kowalczyk Paul 12-NOV-51 558 29-JUL-03 19-JUN-03 703 Davis Linda 17-JUL-02 509 21-JUL-03 22-MAY-03 307 Jones J.C. 17-JUL-02 509 21-JUL-03 22-MAY-03 439 Wright Chasity 23-APR-73 235 696 Vanderchuck Keith 08-AUG-68 504 15-JUN-03 966 Mcginnis Allen 03-MAY-59 504 15-JUN-03 669 Sakic Joe 16-SEP-76 504 15-JUN-03 22 rows selected 3. PT_ID BALANCE DUEDATE PHONE ADDR CITY ST ZIP PT_INS -------------------- ---------- --------- ---------- ------------------------------ -------------------- -- ----- -------------------- 168 15650 21-AUG-03 833-9569 128 W. APPLE #4 Jonesboro IL 62952 SIH 331 300 09-SEP-03 833-5587 3434 Mulberry St. Anna IL 62906 BCBS 313 0 01-JAN-04 893-9987 334 Tailgate Ln COBDEN IL 62920 Military 816 0 01-JAN-04 833-6654 8814 W. Apple JONESBORO IL 62952 SIH 314 100 31-MAR-03 457-6658 445 Oak St. Carbondale IL 62901 BCBS
  • 7. 264 35000 11-JAN-03 942-8065 8898 Bighill Driver HERRIN IL 62948 MediSupplA 103 4500 01-JUL-03 833-5547 298 Murphy School Rd Anna IL 62906 HealthCare 108 0 01-JAN-05 833-5542 334 Pansie Hill Rd. JONESBORO IL 62952 HealthCare 943 0 01-JAN-07 529-9963 456 E. Grand #14 Carbondale IL 62901 Military 847 98000 31-JAN-02 549-8854 6543 W. Parkview Ln. Carbondale IL 62901 BCBS 504 0 01-JAN-03 549-6139 6657 N. Allen Carbondale IL 62901 QualityCare 809 450 19-JUL-03 687-8852 3345 Hwy 127 N. Murphysboro IL 62966 QualityCare 703 225 31-AUG-03 529-8332 909 N. Brown St. Carbondale IL 62901 HealthCare 696 79850 15-JUL-03 549-7231 5546 W. James Carbondale IL 62901 BCBS 966 98700 15-JUL-03 833-5375 9009 Taylor Ave. Anna IL 62906 BCBS 267 0 01-JAN-05 942-3321 6755 US Route 148 HERRIN IL 62948 QualityCare 307 450 31-AUG-03 457-6967 234 N. Allen Carbondale IL 62901 HealthCare 719 0 01-JAN-04 549-7848 867 Henderson St. Carbondale IL 62901 HealthCare 439 500 31-AUG-03 833-5541 4456 N. Springer Anna IL 62906 QualityCare 315 1500 14-SEP-03 833-6272 404 Williford Rd. JONESBORO IL 62952 HealthCare 163 0 01-JAN-04 833-2133 129 Fountain St. Anna IL 62906 HealthCare 669 128450 15-JUL-03 833-6654 353 Tin Bender Rd. Jonesboro IL 62952 BCBS 22 rows selected 4. First Name Last Name Birth Date -------------------- -------------------- ---------- Paul James 14-MAR-97 Brian Anderson 31-MAR-48 Scott James 26-MAR-33 Jason Smith 12-DEC-99 Susan Porter 14-NOV-67 Debbie Saillez 09-SEP-55 Anthony Rogers 01-JAN-42 Stephanie Walters 26-JAN-45 Lynn Westra 12-JUL-57
  • 8. Jennifer Poole 13-MAY-02 Ryan Baily 25-DEC-77 Lewis Crow 10-NOV-49 John Cochran 28-MAR-48 Becky Roach 08-SEP-75 John Jackson 08-NOV-43 Paul Kowalczyk 12-NOV-51 Linda Davis 17-JUL-02 J.C. Jones 17-JUL-02 Chasity Wright 23-APR-73 Keith Vanderchuck 08-AUG-68 Allen Mcginnis 03-MAY-59 Joe Sakic 16-SEP-76 22 rows selected 5. NOW ---------- 05-06-2014 6. Days Since Appt ---------------- It has been 3992,days since Paul James last visit. It has been 3992,days since Brian Anderson last visit. It has been 3973,days since Scott James last visit. It has been 4009,days since Jason Smith last visit. It has been 4084,days since Susan Porter last visit. It has been 3992,days since Debbie Saillez last visit. It has been 4143,days since Anthony Rogers last visit. It has been 4163,days since Stephanie Walters last visit. It has been 4111,days since Lynn Westra last visit. It has been 3992,days since Jennifer Poole last visit. It has been 3987,days since Ryan Baily last visit. It has been 4449,days since Lewis Crow last visit. It has been 4508,days since John Cochran last visit. It has been 4508,days since Becky Roach last visit. It has been 4195,days since John Jackson last visit. It has been 3974,days since Paul Kowalczyk last visit. It has been 4002,days since Linda Davis last visit.
  • 9. It has been 4002,days since J.C. Jones last visit. It has been ,days since Chasity Wright last visit. It has been 3978,days since Keith Vanderchuck last visit. It has been 3978,days since Allen Mcginnis last visit. It has been 3978,days since Joe Sakic last visit. 22 rows selected 7. DOCs w/ PTs by: DOC ID ---------------------- 432 504 389 558 235 509 356 7 rows selected *Same* But Has Duplicates ------------------------- 432 235 235 509 235 235 504 504 235 389 235 235 356 235 235 558 509
  • 10. 509 235 504 504 504 22 rows selected 8. DOC_NAME DATEHIRED -------------------- --------- Stevenson 30-JUN-79 Borque 30-JUN-89 Harrison 05-DEC-94 Robertson 02-MAR-95 James 02-MAY-95 Lewis 21-JAN-96 Thompson 18-MAR-97 Cotner 16-JUN-98 Smith 22-JUN-98 James 01-AUG-98 Pronger 18-DEC-99 Vester 09-JAN-02 12 rows selected DOC_NAME DATEHIRED -------------------- --------- Vester 09-JAN-02 Pronger 18-DEC-99 James 01-AUG-98 Smith 22-JUN-98 Cotner 16-JUN-98 Thompson 18-MAR-97 Lewis 21-JAN-96 James 02-MAY-95 Robertson 02-MAR-95 Harrison 05-DEC-94 Borque 30-JUN-89 Stevenson 30-JUN-79
  • 11. 12 rows selected 9. Days Since Appt -------------- 439-Chasity Wright , days since last appt. 313-Scott James 3973, days since last appt. 809-Paul Kowalczyk 3974, days since last appt. 966-Allen Mcginnis 3978, days since last appt. 696-Keith Vanderchuck 3978, days since last appt. 669-Joe Sakic 3978, days since last appt. 108-Ryan Baily 3987, days since last appt. 168-Paul James 3992, days since last appt. 331-Brian Anderson 3992, days since last appt. 103-Jennifer Poole 3992, days since last appt. 315-Debbie Saillez 3992, days since last appt. 307-J.C. Jones 4002, days since last appt. 703-Linda Davis 4002, days since last appt. 816-Jason Smith 4009, days since last appt. 314-Susan Porter 4084, days since last appt. 267-Lynn Westra 4111, days since last appt. 719-Anthony Rogers 4143, days since last appt. 264-Stephanie Walters 4163, days since last appt. 504-John Jackson 4195, days since last appt. 943-Lewis Crow 4449, days since last appt. 163-Becky Roach 4508, days since last appt. 847-John Cochran 4508, days since last appt. 22 rows selected 10. DOCTOR CHARGE PER APPT LESS $40 -------------------- ------------------------ Vester 40 Lewis 40 Pronger 40 Thompson 65 Harrison 75 James 80 Cotner 85 James 85
  • 12. Robertson 90 Borque 95 10 rows selected 11. Name Days Until Next Appt ----------------------------------------- -------------------- Paul James 30 Brian Anderson 30 Scott James 30 Debbie Saillez 30 Paul Kowalczyk 40 12. PT_ID PT_LNAME PT_FNAME PTDOB DOC_ID NEXTAPPTD LASTAPPTD ---------- -------------------- -------------------- --------- ---------- --------- --------- 168 James Paul 14-MAR-97 432 01-JUL-03 01-JUN-03 313 James Scott 26-MAR-33 235 20-JUL-03 20-JUN-03 13. PT_ID BALANCE -------------------- ---------- 331 300 809 450 307 450 439 500 14. DOC_NAME DOC_ID AREA -------------------- ---------- -------------------- Harrison 432 Pediatrics Vester 509 Pediatrics Lewis 389 Pediatrics Smith 235 Family Practice 15.
  • 13. DOC_ID DOC_NAME ANNUAL_BONUS ---------- -------------------- ------------ 509 Vester 239 Pronger 100 Stevenson 16. PT_ID BALANCE DUEDATE PHONE ADDR CITY ST ZIP PT_INS -------------------- ---------- --------- ---------- ------------------------------ -------------------- -- ----- -------------------- 504 0 01-JAN-03 549-6139 6657 N. Allen Carbondale IL 62901 QualityCare 307 450 31-AUG-03 457-6967 234 N. Allen Carbondale IL 62901 HealthCare 17. PT_ID BALANCE DUEDATE -------------------- ---------- --------- 168 15650 21-AUG-03 264 35000 11-JAN-03 847 98000 31-JAN-02 696 79850 15-JUL-03 966 98700 15-JUL-03 669 128450 15-JUL-03 6 rows selected 18. PT_ID BALANCE DUEDATE PHONE ADDR CITY ST ZIP PT_INS -------------------- ---------- --------- ---------- ------------------------------ -------------------- -- ----- -------------------- 168 15650 21-AUG-03 833-9569 128 W. APPLE #4 Jonesboro IL 62952 SIH 816 0 01-JAN-04 833-6654 8814 W. Apple JONESBORO IL 62952 SIH 847 98000 31-JAN-02 549-8854 6543 W. Parkview Ln. Carbondale IL 62901 BCBS 966 98700 15-JUL-03 833-5375 9009 Taylor Ave. Anna IL 62906 BCBS 669 128450 15-JUL-03 833-6654 353 Tin Bender Rd. Jonesboro IL 62952 BCBS 19.
  • 14. PT_ID PT_LNAME PT_FNAME PTDOB DOC_ID NEXTAPPTD LASTAPPTD ---------- -------------------- -------------------- --------- ---------- --------- --------- 168 James Paul 14-MAR-97 432 01-JUL-03 01-JUN-03 331 Anderson Brian 31-MAR-48 235 01-JUL-03 01-JUN-03 313 James Scott 26-MAR-33 235 20-JUL-03 20-JUN-03 816 Smith Jason 12-DEC-99 509 15-NOV-03 15-MAY-03 314 Porter Susan 14-NOV-67 235 01-OCT-03 01-MAR-03 315 Saillez Debbie 09-SEP-55 235 01-JUL-03 01-JUN-03 719 Rogers Anthony 01-JAN-42 504 01-NOV-03 01-JAN-03 264 Walters Stephanie 26-JAN-45 504 12-DEC-03 12-DEC-02 267 Westra Lynn 12-JUL-57 235 02-FEB-04 02-FEB-03 103 Poole Jennifer 13-MAY-02 389 01-DEC-03 01-JUN-03 108 Baily Ryan 25-DEC-77 235 06-JUN-05 06-JUN-03 943 Crow Lewis 10-NOV-49 235 01-JUL-05 01-MAR-02 847 Cochran John 28-MAR-48 356 02-DEC-05 01-JAN-02 163 Roach Becky 08-SEP-75 235 01-DEC-05 01-JAN-02 504 Jackson John 08-NOV-43 235 21-JUL-03 10-NOV-02 809 Kowalczyk Paul 12-NOV-51 558 29-JUL-03 19-JUN-03 703 Davis Linda 17-JUL-02 509 21-JUL-03 22-MAY-03 307 Jones J.C. 17-JUL-02 509 21-JUL-03 22-MAY-03 439 Wright Chasity 23-APR-73 235 696 Vanderchuck Keith 08-AUG-68 504 15-JUN-03 966 Mcginnis Allen 03-MAY-59 504 15-JUN-03 669 Sakic Joe 16-SEP-76 504 15-JUN-03 22 rows selected 20. PT_ID PT_LNAME PT_FNAME PTDOB DOC_ID NEXTAPPTD LASTAPPTD ---------- -------------------- -------------------- --------- ---------- --------- --------- 313 James Scott 26-MAR-33 235 20-JUL-03 20-JUN-03