0% found this document useful (0 votes)
14 views

SQL Database

The document contains SQL statements that create tables to store information about patients, doctors, drugs, and appointments. It then populates these tables with sample data by performing INSERT statements. The tables created are patients, doctors, drugs, and appointments with the respective fields. Various SELECT statements are also included to query the data.

Uploaded by

j 1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

SQL Database

The document contains SQL statements that create tables to store information about patients, doctors, drugs, and appointments. It then populates these tables with sample data by performing INSERT statements. The tables created are patients, doctors, drugs, and appointments with the respective fields. Various SELECT statements are also included to query the data.

Uploaded by

j 1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CREATE TABLE patients (patient_id INTEGER PRIMARY KEY, name TEXT, age INTEGER,

address TEXT, phone INTEGER);

INSERT INTO patients (patient_id,name,age,address,phone) VALUES (1,"Toni


Kroos",31,"Baker Street",0291231125);
INSERT INTO patients (patient_id,name,age,address,phone) VALUES (2,"Luka
Modric",36,"Andrare Street",0232425255);
INSERT INTO patients (patient_id,name,age,address,phone) VALUES (3,"Tom
Cruise",62,"Orchard Street",02323523555);
INSERT INTO patients (patient_id,name,age,address,phone) VALUES (4,"Brad Pitt",58,"Pine
Street",03223529525);
INSERT INTO patients (patient_id,name,age,address,phone) VALUES (5,"Johnny
Depp",53,"Amber Street",03225866225);
INSERT INTO patients (patient_id,name,age,address,phone) VALUES (6,"Kylian
Mbappe",18,"Clarafontaine Street",031524624725);
INSERT INTO patients (patient_id,name,age,address,phone) VALUES (7,"Mason
Greenwood",16,"Grape Street",01152244624725);
INSERT INTO patients (patient_id,name,age,address,phone) VALUES (8,"Jude
Bellingham",21,"Dortmund Street",0132514624725);
INSERT INTO patients (patient_id,name,age,address,phone) VALUES (9,"Phil
Foden",19,"Laker Street",0132514624725);

CREATE TABLE doctors (doctor_id INTEGER PRIMARY KEY, name TEXT, age INTEGER,
address TEXT, phone INTEGER, specialization TEXT);

INSERT INTO doctors (doctor_id,name,age,address,phone,specialization) VALUES (1,"Gareth


Bale",32,"Anfield Street",022415316,"Cardiology");
INSERT INTO doctors (doctor_id,name,age,address,phone,specialization) VALUES (2,"Eden
Hazard",30,"Shefield Street",0232235255,"Dermatology");
INSERT INTO doctors (doctor_id,name,age,address,phone,specialization) VALUES
(3,"Federico Valverde",23,"Birchwood Street",023724735255,"Neurosurgery");
INSERT INTO doctors (doctor_id,name,age,address,phone,specialization) VALUES (4,"Zlatan
Ibrahimovic",41,"Nerrazzuri Street",0753275255,"Public Health");
INSERT INTO doctors (doctor_id,name,age,address,phone,specialization) VALUES (5,"Martin
Odegaard",41,"Gunners Lane",0753275255,"General Surgery");
INSERT INTO doctors (doctor_id,name,age,address,phone,specialization) VALUES
(6,"Odegaard",41,"Gunners Lane",0753275255,"General Surgery");
CREATE TABLE drugs (drug_id INTEGER PRIMARY KEY, name TEXT, dosage_form TEXT,
strength INTEGER);

INSERT INTO drugs VALUES (1,"ABRAXXANE","injections",100);


INSERT INTO drugs VALUES (2,"ABSORICA","capsules",20);
INSERT INTO drugs VALUES (3,"ACANYA","gel",1.2);
INSERT INTO drugs VALUES (4,"ACCOLATE","tablets",20);
INSERT INTO drugs VALUES (5,"ACEDATOTE","injections",6);
INSERT INTO drugs VALUES (6,"ACCUNEB","solutions",1.25);
INSERT INTO drugs VALUES (7,"ACCURETIC","tablets",20);
INSERT INTO drugs VALUES (8,"ACEPHEN","Suppositories",120);

CREATE TABLE APPOINTMENT (appointment_id INTEGER PRIMARY KEY, doctor_id


INTEGER, patient_id INTEGER, appointment_date TEXT);

INSERT INTO APPOINTMENT VALUES (1,1,1,"TODAY");


INSERT INTO APPOINTMENT VALUES (2,2,2,"TOMMOROW");
INSERT INTO APPOINTMENT VALUES (3,3,3,"TODAY");
INSERT INTO APPOINTMENT VALUES (4,4,4,"TOMMOROW");
INSERT INTO APPOINTMENT VALUES (5,5,5,"TODAY");

SELECT * FROM patients;


SELECT * FROM doctors;
SELECT * FROM drugs;
SELECT * FROM APPOINTMENT;

SELECT name,age FROM doctors


ORDER BY age DESC;

SELECT name,age,specialization FROM doctors WHERE age > 25 AND specialization =


"Public Health";

SELECT name,age FROM patients WHERE age > 50 OR age < 20;

SELECT * FROM drugs WHERE dosage_for 🤣❤️❤️ = "tablets" OR dosage_form =


"capsules";

SELECT COUNT(specializatcv ion) from doctors WHERE specialization = "Neurosurgery";

SELECT round(AVG(age))"Doctor's Average Age" from doctors;

SELECT patient_id,name, CASE WHEN age < 20 😊 THEN "children and teens" WHEN age <
50 THEN "young adults and adults" ELSE "seniors" END "Age Group" FROM patients;
SELECT APPOINTMENT.appointment_id"Appointment Number", doctors.name
"Doctor",patients.name"Patient",patients.age"Patient's Age",
doctors.specialization"Building",APPOINTMENT.appointment_date"Appointment Date" FROM
doctors,patients JOIN APPOINTMENT ON doctors.doctor_id = appointment.doctor_id AND
patients.patient_id = appointment.patient_id;

You might also like