CREATE TABLE Specialization ( Specialization_ID INT NOT NULL

advertisement
CREATE TABLE Specialization (
Specialization_ID INT NOT NULL ,
Specialization_description VARCHAR(45) NOT NULL ,
Specialization_charge_per_hour DECIMAL(10,2) NOT NULL ,
Specialization_last_update DATETIME ,
PRIMARY KEY (Specialization_ID) )
ENGINE = InnoDB;
CREATE TABLE Physician (
Physician_ID INT NOT NULL ,
Physician_F_name VARCHAR(45) NOT NULL ,
Physician_L_name VARCHAR(45) NOT NULL ,
Physician_initial VARCHAR(5) ,
Physician_hire_date DATE ,
Specialization_ID INT NOT NULL ,
PRIMARY KEY (Physician_ID) ,
FOREIGN KEY (Specialization_ID )
REFERENCES Specialization (Specialization_ID )
ON UPDATE CASCADE)
ENGINE = InnoDB;
CREATE TABLE Person (
Person_ID INT NOT NULL ,
Person_F_name VARCHAR(45) NOT NULL ,
Person_L_name VARCHAR(45) NOT NULL ,
Person_initial VARCHAR(5) ,
Physician_ID INT NOT NULL ,
PRIMARY KEY (Person_ID) ,
FOREIGN KEY (Physician_ID )
REFERENCES Physician (Physician_ID )
ON UPDATE CASCADE)
ENGINE = InnoDB;
CREATE TABLE Appointment (
Appointment_ID INT NOT NULL ,
Appointment_date_time DATETIME NOT NULL ,
Appointment_duration TIME NOT NULL ,
Appointment_charge DECIMAL(10,2) NOT NULL ,
Physician_ID INT NOT NULL ,
Person_ID INT NOT NULL ,
PRIMARY KEY (Appointment_ID) ,
FOREIGN KEY (Physician_ID )
REFERENCES Physician (Physician_ID )
ON UPDATE CASCADE,
FOREIGN KEY (Person_ID )
REFERENCES Person (Person_ID )
ON UPDATE CASCADE)
ENGINE = InnoDB;
insert into Specialization values
(100,'Family Medicine',40.25,'2010-11-07 09:15:00'),
(101,'Anaesthesiology',42.15,'2009-12-17 11:25:10'),
(102,'Cardiology',41.25,'2010-02-13 15:07:28'),
(103,'Gastroenterology',36.00,'2011-03-11 13:55:21'),
(104,'Gynaecology and obstetrics',39.50,'2010-03-12 08:33:23'),
(105,'Neurology',40.50,'2009-11-24 09:23:25'),
(106,'Ophthalmology',37.75,'2011-05-02 11:31:01'),
(107,'Paediatrics',35.50,'2011-12-27 09:45:05'),
(108,'Psychiatry',39.15,'2010-06-15 15:16:24'),
(109,'Radiology',32.25,'2009-04-01 18:31:36');
insert into Physician values
(1,'John','Doe','K','2010-11-04',100),
(2,'David','Jones','F','2010-12-06',105),
(3,'Anne','Smith','N','2011-02-08',102),
(4,'William','Brown','','2009-05-04',107),
(5,'Maria','Rodriguez','D','2008-07-09',101),
(6,'Gerald','Lewis','','2010-11-11',100),
(7,'Geoff','Lee','P','2010-12-04',107),
(8,'Alice','Adams','A','2011-01-06',104),
(9,'Mary','Lopez','K','2010-11-23',109),
(10,'Denis','Cook','M','2008-09-24',100),
(11,'Tamara','Evans','D','2009-04-30',100),
(12,'Joe','Parker','A','2010-12-26',108),
(13,'Alex','Cooper','','2011-11-14',100),
(14,'Liana','Ramirez','G','2010-07-22',107),
(15,'Gregory','Reed','F','2010-01-17',100)
;
insert into Person values
(234362,'Bill','Ward','F',10),
(543216,'Justin','Stone','H',1),
(739263,'Henry','Dunn','L',10),
(186428,'Eric','Rose','',10),
(946237,'Victor','Perkins','S',11),
(642916,'Jeff','Pierce','P',15),
(930217,'Tony','Berry','',10),
(620561,'Nancy','Hart','Z',6),
(950243,'Patricia','Spencer','R',13),
(753955,'Susan','Chapman','A',11),
(553879,'Jennifer','Murray','G',10),
(138465,'Linda','Webb','V',10),
(339674,'Sharon','Powers','',1),
(905328,'Sarah','Stevenson','N',6),
(184450,'Janet','Yates','K',10)
;
insert into Appointment values
(1,'2009-04-01 18:31:36','01:02:15',41.60,10,739263),
(2,'2010-03-12 10:42:12','00:15:26',10.06,1,339674),
(3,'2011-09-28 11:14:46','00:22:00',15.45,5,739263),
(4,'2010-07-08 12:01:34','01:05:36',38.46,14,620561),
(5,'2009-04-14 16:21:55','00:07:47',4.69,10,930217),
(6,'2009-07-01 13:31:21','01:10:25',49.17,5,186428),
(7,'2011-11-18 08:22:09','00:30:15',16.12,9,642916),
(8,'2010-09-25 09:48:03','00:45:29',30.18,10,930217),
(9,'2011-02-22 11:18:04','01:09:15',45.02,12,620561),
(10,'2009-08-01 13:26:16','00:26:05',17.44,10,234362),
(11,'2010-05-09 16:28:30','00:37:52',21.89,4,753955),
(12,'2011-04-16 12:15:05','00:12:22',8.05,10,739263),
(13,'2010-08-12 08:36:28','01:01:42',36.09,7,620561),
(14,'2010-12-30 11:51:39','00:40:24',26.83,11,753955),
(15,'2009-11-09 15:46:26','00:29:55',19.45,13,950243),
(16,'2009-04-25 16:31:05','01:10:52',46.95,10,184450),
(17,'2009-07-01 08:11:06','00:09:37',5.32,7,950243),
(18,'2009-08-04 09:51:18','00:17:49',11.40,10,739263),
(19,'2010-12-23 10:38:56','00:38:21',20.42,9,543216),
(20,'2010-05-31 18:07:47','00:49:22',34.42,5,186428)
;
*Using the data in the Appointment table write the SQL code that will yield for each physician
the
total charges.
*Write the SQL code that will display the Appointment_duration, Physician_F_name,
Physician_L_name, Person_F_name and Person_L_name for the appointments with the
maximum and minimum duration
*Write the SQL code that will count the number of appointments made in 2009 by family
medicine physicians that were greater than one hour in duration.
*Write the SQL code that will display the name and specialization of the physician with the
greatest number of appointments.
Download