Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

SAEZ, JOHN CARLO C.

MIDTERM EXAM
BSIT – NW3C

2. Create a New User ITStaff with a password hospitalstaff. Prove that the new user is created.

CREATE USER ITStaff

IDENTIFIED BY hospitalstaff;
SAEZ, JOHN CARLO C. MIDTERM EXAM
BSIT – NW3C

3. Provide privileges to the user ITStaff by allowing it to create table, sequence, and view. Make sure
to log-in to the Oracle server to allow these privileges. Confirm that the privileges are granted
successfully.

GRANT create table, create sequence, create view

TO ITStaff;
SAEZ, JOHN CARLO C. MIDTERM EXAM
BSIT – NW3C

3. Create all the necessary tables and insert the records based on the given table.

CREATE TABLE PATIENT (

patient_id number NOT NULL PRIMARY KEY,

Lastname varchar2(20) NOT NULL,

Firstname varchar2(20) NOT NULL,

Middlename varchar2(20) NOT NULL,

Address varchar2(20) NOT NULL,

Sex varchar2(20) NOT NULL,

Nationality varchar2(20) NOT NULL,

admission_date date

);

CREATE TABLE DOCTOR


SAEZ, JOHN CARLO C. MIDTERM EXAM
BSIT – NW3C

doctor_id number NOT NULL PRIMARY KEY,

Doctors_information varchar2(20)

);
SAEZ, JOHN CARLO C. MIDTERM EXAM
BSIT – NW3C

CREATE TABLE PatientDiagnosis

(Patient_DiagnosisID number NOT NULL PRIMARY KEY,

Symptoms varchar2(20),

Severity varchar2(20),

Laboratory varchar2(20),

Medication varchar2(20),

Treatment varchar2(20),

patient_id number,

doctor_id number);
SAEZ, JOHN CARLO C. MIDTERM EXAM
BSIT – NW3C

CREATE TABLE BILLING

billing_id number NOT NULL PRIMARY KEY,

Bills number,

Patient_DiagnosisID number

);

CREATE TABLE PAYMENT

payment_id number NOT NULL PRIMARY KEY,

Status_of_payment varchar2(20),

billing_id number

);
SAEZ, JOHN CARLO C. MIDTERM EXAM
BSIT – NW3C

CREATE TABLE ROOM

room_id number NOT NULL PRIMARY KEY,

Patient_ID number

);

CREATE TABLE admission_discharge

admission_dischargeID number NOT NULL PRIMARY KEY,

payment_id number

);
SAEZ, JOHN CARLO C. MIDTERM EXAM
BSIT – NW3C

A. Use the Select statement to display all the records of Filipino patients.

SELECT * FROM PATIENT

WHERE Nationality = 'Filipino';

B. Show all the records of the patients with Chest pain.

SELECT* FROM PATIENT

INNER JOIN PatientDiagnosis ON PATIENT.patient_id = PatientDiagnosis.Patient_DiagnosisID

WHERE PatientDiagnosis.Symptoms = 'Chest Pain';

C. Display the names of all patients that have severe severity.

SELECT* FROM PATIENT

INNER JOIN PatientDiagnosis ON PATIENT.patient_id = PatientDiagnosis.Patient_DiagnosisID

WHERE PatientDiagnosis.Severity = 'Severe';


SAEZ, JOHN CARLO C. MIDTERM EXAM
BSIT – NW3C

D. Show the list of patients who has Fever and Diarrhea.

SELECT* FROM PATIENT

INNER JOIN PatientDiagnosis ON PATIENT.patient_id = PatientDiagnosis.Patient_DiagnosisID

WHERE PatientDiagnosis.Symptoms = any('Diarrhea', 'Fever');

E. Count the number of patients who have moderate severity.

SELECT COUNT (*)

FROM PatientDiagnosis

WHERE Severity = 'Moderate';

F. Show the list of patients living in Balanga.

SELECT * FROM PATIENT

WHERE Address = 'Balanga';

G. How many patients are male? Female? Show the list of patients.
SAEZ, JOHN CARLO C. MIDTERM EXAM
BSIT – NW3C

SELECT Sex, COUNT (*)

FROM PATIENT

GROUP BY Sex;

H. Count the number of Filipino patients. How many are Americans? Chinese?

SELECT Nationality, COUNT (*)

FROM PATIENT

GROUP BY Nationality;
SAEZ, JOHN CARLO C. MIDTERM EXAM
BSIT – NW3C

I. Change the field name admission date to adm_date.

ALTER TABLE PATIENT

RENAME COLUMN

admission_date TO adm_date;

J. Show the table structure of the patient's table.

DESCRIBE PATIENT;

K. Show the list of patients who already paid their bills.

SELECT* FROM PATIENT

INNER JOIN PAYMENT ON PATIENT.patient_id = PAYMENT.payment_id

WHERE PAYMENT.Status_of_payment = any('Fully Paid','Fully-Paid');


SAEZ, JOHN CARLO C. MIDTERM EXAM
BSIT – NW3C

L. Display the list of patients with Existing Balance.

SELECT* FROM PATIENT

INNER JOIN PAYMENT ON PATIENT.patient_id = PAYMENT.payment_id

WHERE PAYMENT.Status_of_payment = 'With Balance';

M. Show the list of the patient with the highest bills?

SELECT MAX(Bills)

FROM BILLING;

N. Display the name of the patient with the lowest bills.

SELECT* FROM PATIENT

INNER JOIN BILLING ON PATIENT.patient_id = BILLING.billing_id

WHERE BILLING.bills <= 10000;


SAEZ, JOHN CARLO C. MIDTERM EXAM
BSIT – NW3C

O. Display all the records using the SQL statement.

SELECT* FROM PATIENT

INNER JOIN Billing ON

Billing.billing_id = PATIENT.patient_id

INNER JOIN PatientDiagnosis ON

PatientDiagnosis.Patient_DiagnosisID = PATIENT.patient_id;

You might also like