db_id
stringclasses 127
values | query
stringlengths 20
523
| question
stringlengths 16
224
| schema
stringclasses 127
values |
---|---|---|---|
behavior_monitoring | SELECT count(*) FROM ADDRESSES WHERE zip_postcode = "197" | How many addresses have zip code 197? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT count(DISTINCT incident_type_code) FROM Behavior_Incident | How many distinct incident type codes are there? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT DISTINCT detention_type_code FROM Detention | Return all distinct detention type codes. | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT date_incident_start , date_incident_end FROM Behavior_Incident WHERE incident_type_code = "NOISE" | What are the start and end dates for incidents with incident type code "NOISE"? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT detention_summary FROM Detention | Return all detention summaries. | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT cell_mobile_number , email_address FROM STUDENTS | Return the cell phone number and email address for all students. | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT email_address FROM Students WHERE first_name = "Emma" AND last_name = "Rohan" | What is the email of the student with first name "Emma" and last name "Rohan"? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT count(DISTINCT student_id) FROM Students_in_Detention | How many distinct students have been in detention? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT gender FROM TEACHERS WHERE last_name = "Medhurst" | What is the gender of the teacher with last name "Medhurst"? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT incident_type_description FROM Ref_Incident_Type WHERE incident_type_code = "VIOLENCE" | What is the incident type description for the incident type with code "VIOLENCE"? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT max(monthly_rental) , min(monthly_rental) FROM Student_Addresses | Find the maximum and minimum monthly rental for all student addresses. | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT first_name FROM Teachers WHERE email_address LIKE '%man%' | Find the first names of teachers whose email address contains the word "man". | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT * FROM Assessment_Notes ORDER BY date_of_notes ASC | List all information about the assessment notes sorted by date in ascending order. | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT city FROM Addresses ORDER BY city | List all cities of addresses in alphabetical order. | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT first_name , last_name FROM Teachers ORDER BY last_name | Find the first names and last names of teachers in alphabetical order of last name. | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT * FROM Student_Addresses ORDER BY monthly_rental DESC | Find all information about student addresses, and sort by monthly rental in descending order. | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT T1.student_id , T2.first_name FROM Assessment_Notes AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id GROUP BY T1.student_id ORDER BY count(*) DESC LIMIT 1 | Find the id and first name of the student that has the most number of assessment notes? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT T1.teacher_id , T2.first_name FROM Assessment_Notes AS T1 JOIN Teachers AS T2 ON T1.teacher_id = T2.teacher_id GROUP BY T1.teacher_id ORDER BY count(*) DESC LIMIT 3 | Find the ids and first names of the 3 teachers that have the most number of assessment notes? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT T1.student_id , T2.last_name FROM Behavior_Incident AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id GROUP BY T1.student_id ORDER BY count(*) DESC LIMIT 1 | Find the id and last name of the student that has the most behavior incidents? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT T1.teacher_id , T2.last_name FROM Detention AS T1 JOIN Teachers AS T2 ON T1.teacher_id = T2.teacher_id WHERE T1.detention_type_code = "AFTER" GROUP BY T1.teacher_id ORDER BY count(*) DESC LIMIT 1 | Find the id and last name of the teacher that has the most detentions with detention type code "AFTER"? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT T1.student_id , T2.first_name FROM Student_Addresses AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id GROUP BY T1.student_id ORDER BY AVG(monthly_rental) DESC LIMIT 1 | What are the id and first name of the student whose addresses have the highest average monthly rental? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT T2.address_id , T1.city FROM Addresses AS T1 JOIN Student_Addresses AS T2 ON T1.address_id = T2.address_id GROUP BY T2.address_id ORDER BY AVG(monthly_rental) DESC LIMIT 1 | Find the id and city of the student address with the highest average monthly rental. | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT T1.incident_type_code , T2.incident_type_description FROM Behavior_Incident AS T1 JOIN Ref_Incident_Type AS T2 ON T1.incident_type_code = T2.incident_type_code GROUP BY T1.incident_type_code ORDER BY count(*) DESC LIMIT 1 | What are the code and description of the most frequent behavior incident type? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT T1.detention_type_code , T2.detention_type_description FROM Detention AS T1 JOIN Ref_Detention_Type AS T2 ON T1.detention_type_code = T2.detention_type_code GROUP BY T1.detention_type_code ORDER BY count(*) ASC LIMIT 1 | What are the code and description of the least frequent detention type ? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT T1.date_of_notes FROM Assessment_Notes AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id WHERE T2.first_name = "Fanny" | Find the dates of assessment notes for students with first name "Fanny". | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT T1.text_of_notes FROM Assessment_Notes AS T1 JOIN Teachers AS T2 ON T1.teacher_id = T2.teacher_id WHERE T2.last_name = "Schuster" | Find the texts of assessment notes for teachers with last name "Schuster". | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT T1.date_incident_start , date_incident_end FROM Behavior_Incident AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id WHERE T2.last_name = "Fahey" | Find the start and end dates of behavior incidents of students with last name "Fahey". | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT T1.datetime_detention_start , datetime_detention_end FROM Detention AS T1 JOIN Teachers AS T2 ON T1.teacher_id = T2.teacher_id WHERE T2.last_name = "Schultz" | Find the start and end dates of detentions of teachers with last name "Schultz". | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT T2.address_id , T1.zip_postcode FROM Addresses AS T1 JOIN Student_Addresses AS T2 ON T1.address_id = T2.address_id ORDER BY monthly_rental DESC LIMIT 1 | What are the id and zip code of the address with the highest monthly rental? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT T2.cell_mobile_number FROM Student_Addresses AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id ORDER BY T1.monthly_rental ASC LIMIT 1 | What is the cell phone number of the student whose address has the lowest monthly rental? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT T2.monthly_rental FROM Addresses AS T1 JOIN Student_Addresses AS T2 ON T1.address_id = T2.address_id WHERE T1.state_province_county = "Texas" | What are the monthly rentals of student addresses in Texas state? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT T2.first_name , T2.last_name FROM Addresses AS T1 JOIN Students AS T2 ON T1.address_id = T2.address_id WHERE T1.state_province_county = "Wisconsin" | What are the first names and last names of students with address in Wisconsin state? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT T1.line_1 , avg(T2.monthly_rental) FROM Addresses AS T1 JOIN Student_Addresses AS T2 ON T1.address_id = T2.address_id GROUP BY T2.address_id | What are the line 1 and average monthly rentals of all student addresses? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT T1.zip_postcode FROM Addresses AS T1 JOIN Teachers AS T2 ON T1.address_id = T2.address_id WHERE T2.first_name = "Lyla" | What is the zip code of the address where the teacher with first name "Lyla" lives? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT T2.email_address FROM Addresses AS T1 JOIN Teachers AS T2 ON T1.address_id = T2.address_id WHERE T1.zip_postcode = "918" | What are the email addresses of teachers whose address has zip code "918"? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT count(*) FROM STUDENTS WHERE student_id NOT IN ( SELECT student_id FROM Behavior_Incident ) | How many students are not involved in any behavior incident? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT last_name FROM Teachers EXCEPT SELECT T1.last_name FROM Teachers AS T1 JOIN Detention AS T2 ON T1.teacher_id = T2.teacher_id | Find the last names of teachers who are not involved in any detention. | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
behavior_monitoring | SELECT T1.line_1 FROM Addresses AS T1 JOIN Students AS T2 ON T1.address_id = T2.address_id INTERSECT SELECT T1.line_1 FROM Addresses AS T1 JOIN Teachers AS T2 ON T1.address_id = T2.address_id | What are the line 1 of addresses shared by some students and some teachers? | PRAGMA foreign_keys = ON;
CREATE TABLE `Ref_Address_Types` (
`address_type_code` VARCHAR(15) PRIMARY KEY,
`address_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Detention_Type` (
`detention_type_code` VARCHAR(10) PRIMARY KEY,
`detention_type_description` VARCHAR(80)
);
CREATE TABLE `Ref_Incident_Type` (
`incident_type_code` VARCHAR(10) PRIMARY KEY,
`incident_type_description` VARCHAR(80)
);
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`line_1` VARCHAR(120),
`line_2` VARCHAR(120),
`line_3` VARCHAR(120),
`city` VARCHAR(80),
`zip_postcode` VARCHAR(20),
`state_province_county` VARCHAR(50),
`country` VARCHAR(50),
`other_address_details` VARCHAR(255)
);
CREATE TABLE `Students` (
`student_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(40),
`last_name` VARCHAR(40),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`date_first_rental` DATETIME,
`date_left_university` DATETIME,
`other_student_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Teachers` (
`teacher_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`first_name` VARCHAR(80),
`middle_name` VARCHAR(80),
`last_name` VARCHAR(80),
`gender` VARCHAR(1),
`cell_mobile_number` VARCHAR(40),
`email_address` VARCHAR(40),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` )
);
CREATE TABLE `Assessment_Notes` (
`notes_id` INTEGER NOT NULL ,
`student_id` INTEGER,
`teacher_id` INTEGER NOT NULL,
`date_of_notes` DATETIME,
`text_of_notes` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Behavior_Incident` (
`incident_id` INTEGER PRIMARY KEY,
`incident_type_code` VARCHAR(10) NOT NULL,
`student_id` INTEGER NOT NULL,
`date_incident_start` DATETIME,
`date_incident_end` DATETIME,
`incident_summary` VARCHAR(255),
`recommendations` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Detention` (
`detention_id` INTEGER PRIMARY KEY,
`detention_type_code` VARCHAR(10) NOT NULL,
`teacher_id` INTEGER,
`datetime_detention_start` DATETIME,
`datetime_detention_end` DATETIME,
`detention_summary` VARCHAR(255),
`other_details` VARCHAR(255),
FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ),
FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` )
);
CREATE TABLE `Student_Addresses` (
`student_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_address_from` DATETIME NOT NULL,
`date_address_to` DATETIME,
`monthly_rental` DECIMAL(19,4),
`other_details` VARCHAR(255),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
CREATE TABLE `Students_in_Detention` (
`student_id` INTEGER NOT NULL,
`detention_id` INTEGER NOT NULL,
`incident_id` INTEGER NOT NULL,
FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ),
FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ),
FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` )
);
INSERT INTO Ref_Address_Types (`address_type_code`, `address_type_description`) VALUES ('BILL', 'Billing')INSERT INTO Ref_Detention_Type (`detention_type_code`, `detention_type_description`) VALUES ('BREAK ', 'During Break time')INSERT INTO Ref_Incident_Type (`incident_type_code`, `incident_type_description`) VALUES ('NOISE', 'Noise')INSERT INTO Addresses (`address_id`, `line_1`, `line_2`, `line_3`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '020 Orie Canyon', NULL, NULL, 'North Loyceville', '197', 'Hawaii', 'USA', NULL)INSERT INTO Students (`student_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `cell_mobile_number`, `email_address`, `date_first_rental`, `date_left_university`, `other_student_details`) VALUES (1, 19, 'Emma', 'Frederic', 'Rohan', '235.899.9744', '[email protected]', '2017-12-05 15:20:04', '2018-03-03 03:33:05', NULL)INSERT INTO Teachers (`teacher_id`, `address_id`, `first_name`, `middle_name`, `last_name`, `gender`, `cell_mobile_number`, `email_address`, `other_details`) VALUES (1, 15, 'Lyla', 'Wilson', 'Medhurst', '1', '792.333.7714', '[email protected]', NULL)INSERT INTO Assessment_Notes (`notes_id`, `student_id`, `teacher_id`, `date_of_notes`, `text_of_notes`, `other_details`) VALUES (1, 7, 3, '1978-04-15 04:49:18', NULL, NULL)INSERT INTO Behavior_Incident (`incident_id`, `incident_type_code`, `student_id`, `date_incident_start`, `date_incident_end`, `incident_summary`, `recommendations`, `other_details`) VALUES (1, 'NOISE', 6, '2017-07-09 10:04:13', '2018-03-08 14:08:54', NULL, NULL, NULL)INSERT INTO Detention (`detention_id`, `detention_type_code`, `teacher_id`, `datetime_detention_start`, `datetime_detention_end`, `detention_summary`, `other_details`) VALUES (1, 'AFTER', 7, '2017-09-05 00:38:25', '2018-03-08 02:08:32', NULL, NULL)INSERT INTO Student_Addresses (`student_id`, `address_id`, `date_address_from`, `date_address_to`, `monthly_rental`, `other_details`) VALUES (6, 12, '2017-10-16 13:56:34', '2018-03-15 10:37:19', '826.4319', 'house')INSERT INTO Students_in_Detention (`student_id`, `detention_id`, `incident_id`) VALUES (3, 15, 1) |
assets_maintenance | SELECT T1.asset_id , T1.asset_details FROM Assets AS T1 JOIN Asset_Parts AS T2 ON T1.asset_id = T2.asset_id GROUP BY T1.asset_id HAVING count(*) = 2 INTERSECT SELECT T1.asset_id , T1.asset_details FROM Assets AS T1 JOIN Fault_Log AS T2 ON T1.asset_id = T2.asset_id GROUP BY T1.asset_id HAVING count(*) < 2 | Which assets have 2 parts and have less than 2 fault logs? List the asset id and detail. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT count(*) , T1.maintenance_contract_id FROM Maintenance_Contracts AS T1 JOIN Assets AS T2 ON T1.maintenance_contract_id = T2.maintenance_contract_id GROUP BY T1.maintenance_contract_id | How many assets does each maintenance contract contain? List the number and the contract id. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT count(*) , T1.company_id FROM Third_Party_Companies AS T1 JOIN Assets AS T2 ON T1.company_id = T2.supplier_company_id GROUP BY T1.company_id | How many assets does each third party company supply? List the count and the company id. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT T1.company_id , T1.company_name FROM Third_Party_Companies AS T1 JOIN Maintenance_Engineers AS T2 ON T1.company_id = T2.company_id GROUP BY T1.company_id HAVING count(*) >= 2 UNION SELECT T3.company_id , T3.company_name FROM Third_Party_Companies AS T3 JOIN Maintenance_Contracts AS T4 ON T3.company_id = T4.maintenance_contract_company_id GROUP BY T3.company_id HAVING count(*) >= 2 | Which third party companies have at least 2 maintenance engineers or have at least 2 maintenance contracts? List the company id and name. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT T1.staff_name , T1.staff_id FROM Staff AS T1 JOIN Fault_Log AS T2 ON T1.staff_id = T2.recorded_by_staff_id EXCEPT SELECT T3.staff_name , T3.staff_id FROM Staff AS T3 JOIN Engineer_Visits AS T4 ON T3.staff_id = T4.contact_staff_id | What is the name and id of the staff who recorded the fault log but has not contacted any visiting engineers? | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT T1.engineer_id , T1.first_name , T1.last_name FROM Maintenance_Engineers AS T1 JOIN Engineer_Visits AS T2 GROUP BY T1.engineer_id ORDER BY count(*) DESC LIMIT 1 | Which engineer has visited the most times? Show the engineer id, first name and last name. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT T1.part_name , T1.part_id FROM Parts AS T1 JOIN Part_Faults AS T2 ON T1.part_id = T2.part_id GROUP BY T1.part_id HAVING count(*) > 2 | Which parts have more than 2 faults? Show the part name and id. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT T1.first_name , T1.last_name , T1.other_details , T3.skill_description FROM Maintenance_Engineers AS T1 JOIN Engineer_Skills AS T2 ON T1.engineer_id = T2.engineer_id JOIN Skills AS T3 ON T2.skill_id = T3.skill_id | List all every engineer's first name, last name, details and coresponding skill description. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT T1.fault_short_name , T3.skill_description FROM Part_Faults AS T1 JOIN Skills_Required_To_Fix AS T2 ON T1.part_fault_id = T2.part_fault_id JOIN Skills AS T3 ON T2.skill_id = T3.skill_id | For all the faults of different parts, what are all the decriptions of the skills required to fix them? List the name of the faults and the skill description. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT T1.part_name , count(*) FROM Parts AS T1 JOIN Asset_Parts AS T2 ON T1.part_id = T2.part_id GROUP BY T1.part_name | How many assets can each parts be used in? List the part name and the number. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT T1.fault_description , T2.fault_status FROM Fault_Log AS T1 JOIN Fault_Log_Parts AS T2 ON T1.fault_log_entry_id = T2.fault_log_entry_id | What are all the fault descriptions and the fault status of all the faults recoreded in the logs? | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT count(*) , T1.fault_log_entry_id FROM Fault_Log AS T1 JOIN Engineer_Visits AS T2 ON T1.fault_log_entry_id = T2.fault_log_entry_id GROUP BY T1.fault_log_entry_id ORDER BY count(*) DESC LIMIT 1 | How many engineer visits are required at most for a single fault log? List the number and the log entry id. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT DISTINCT last_name FROM Maintenance_Engineers | What are all the distinct last names of all the engineers? | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT DISTINCT fault_status FROM Fault_Log_Parts | How many fault status codes are recorded in the fault log parts table? | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT first_name , last_name FROM Maintenance_Engineers WHERE engineer_id NOT IN (SELECT engineer_id FROM Engineer_Visits) | Which engineers have never visited to maintain the assets? List the engineer first name and last name. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT asset_id , asset_details , asset_make , asset_model FROM Assets | List the asset id, details, make and model for every asset. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT asset_acquired_date FROM Assets ORDER BY asset_acquired_date ASC LIMIT 1 | When was the first asset acquired? | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT T1.part_id , T1.part_name FROM Parts AS T1 JOIN Part_Faults AS T2 ON T1.part_id = T2.part_id JOIN Skills_Required_To_Fix AS T3 ON T2.part_fault_id = T3.part_fault_id GROUP BY T1.part_id ORDER BY count(*) DESC LIMIT 1 | Which part fault requires the most number of skills to fix? List part id and name. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT T1.part_name FROM Parts AS T1 JOIN Part_Faults AS T2 ON T1.part_id = T2.part_id GROUP BY T1.part_name ORDER BY count(*) ASC LIMIT 1 | Which kind of part has the least number of faults? List the part name. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT T1.engineer_id , T1.first_name , T1.last_name FROM Maintenance_Engineers AS T1 JOIN Engineer_Visits AS T2 ON T1.engineer_id = T2.engineer_id GROUP BY T1.engineer_id ORDER BY count(*) ASC LIMIT 1 | Among those engineers who have visited, which engineer makes the least number of visits? List the engineer id, first name and last name. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT T1.staff_name , T3.first_name , T3.last_name FROM Staff AS T1 JOIN Engineer_Visits AS T2 ON T1.staff_id = T2.contact_staff_id JOIN Maintenance_Engineers AS T3 ON T2.engineer_id = T3.engineer_id | Which staff have contacted which engineers? List the staff name and the engineer first name and last name. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT T1.fault_log_entry_id , T1.fault_description , T1.fault_log_entry_datetime FROM Fault_Log AS T1 JOIN Fault_Log_Parts AS T2 ON T1.fault_log_entry_id = T2.fault_log_entry_id GROUP BY T1.fault_log_entry_id ORDER BY count(*) DESC LIMIT 1 | Which fault log included the most number of faulty parts? List the fault log id, description and record time. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT T1.skill_id , T1.skill_description FROM Skills AS T1 JOIN Skills_Required_To_Fix AS T2 ON T1.skill_id = T2.skill_id GROUP BY T1.skill_id ORDER BY count(*) DESC LIMIT 1 | Which skill is used in fixing the most number of faults? List the skill id and description. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT DISTINCT asset_model FROM Assets | What are all the distinct asset models? | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT asset_make , asset_model , asset_details FROM Assets ORDER BY asset_disposed_date ASC | List the all the assets make, model, details by the disposed date ascendingly. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT part_id , chargeable_amount FROM Parts ORDER BY chargeable_amount ASC LIMIT 1 | Which part has the least chargeable amount? List the part id and amount. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT T1.company_name FROM Third_Party_Companies AS T1 JOIN Maintenance_Contracts AS T2 ON T1.company_id = T2.maintenance_contract_company_id ORDER BY T2.contract_start_date ASC LIMIT 1 | Which company started the earliest the maintenance contract? Show the company name. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT T1.company_name FROM Third_Party_Companies AS T1 JOIN Maintenance_Contracts AS T2 ON T1.company_id = T2.maintenance_contract_company_id JOIN Ref_Company_Types AS T3 ON T1.company_type_code = T3.company_type_code ORDER BY T2.contract_end_date DESC LIMIT 1 | What is the description of the type of the company who concluded its contracts most recently? | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT gender FROM staff GROUP BY gender ORDER BY count(*) DESC LIMIT 1 | Which gender makes up the majority of the staff? | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT T1.staff_name , count(*) FROM Staff AS T1 JOIN Engineer_Visits AS T2 ON T1.staff_id = T2.contact_staff_id GROUP BY T1.staff_name | How many engineers did each staff contact? List both the contact staff name and number of engineers contacted. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
assets_maintenance | SELECT asset_model FROM Assets WHERE asset_id NOT IN (SELECT asset_id FROM Fault_Log) | Which assets did not incur any fault log? List the asset model. | PRAGMA foreign_keys = ON;
CREATE TABLE `Third_Party_Companies` (
`company_id` INTEGER PRIMARY KEY ,
`company_type` VARCHAR(5) NOT NULL,
`company_name` VARCHAR(255),
`company_address` VARCHAR(255),
`other_company_details` VARCHAR(255)
);
CREATE TABLE `Maintenance_Contracts` (
`maintenance_contract_id` INTEGER PRIMARY KEY,
`maintenance_contract_company_id` INTEGER NOT NULL,
`contract_start_date` DATETIME,
`contract_end_date` DATETIME,
`other_contract_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Parts` (
`part_id` INTEGER PRIMARY KEY,
`part_name` VARCHAR(255),
`chargeable_yn` VARCHAR(1),
`chargeable_amount` VARCHAR(20),
`other_part_details` VARCHAR(255)
);
CREATE TABLE `Skills` (
`skill_id` INTEGER PRIMARY KEY,
`skill_code` VARCHAR(20),
`skill_description` VARCHAR(255)
);
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_name` VARCHAR(255),
`gender` VARCHAR(1),
`other_staff_details` VARCHAR(255)
);
CREATE TABLE `Assets` (
`asset_id` INTEGER PRIMARY KEY,
`maintenance_contract_id` INTEGER NOT NULL,
`supplier_company_id` INTEGER NOT NULL,
`asset_details` VARCHAR(255),
`asset_make` VARCHAR(20),
`asset_model` VARCHAR(20),
`asset_acquired_date` DATETIME,
`asset_disposed_date` DATETIME,
`other_asset_details` VARCHAR(255),
FOREIGN KEY (`maintenance_contract_id` )
REFERENCES `Maintenance_Contracts`(`maintenance_contract_id` ),
FOREIGN KEY (`supplier_company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Asset_Parts` (
`asset_id` INTEGER NOT NULL,
`part_id` INTEGER NOT NULL,
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` ),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` )
);
CREATE TABLE `Maintenance_Engineers` (
`engineer_id` INTEGER PRIMARY KEY,
`company_id` INTEGER NOT NULL,
`first_name` VARCHAR(50),
`last_name` VARCHAR(50),
`other_details` VARCHAR(255),
FOREIGN KEY (`company_id` ) REFERENCES `Third_Party_Companies`(`company_id` )
);
CREATE TABLE `Engineer_Skills` (
`engineer_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
CREATE TABLE `Fault_Log` (
`fault_log_entry_id` INTEGER PRIMARY KEY,
`asset_id` INTEGER NOT NULL,
`recorded_by_staff_id` INTEGER NOT NULL,
`fault_log_entry_datetime` DATETIME,
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`asset_id` ) REFERENCES `Assets`(`asset_id` ),
FOREIGN KEY (`recorded_by_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Engineer_Visits` (
`engineer_visit_id` INTEGER PRIMARY KEY,
`contact_staff_id` INTEGER,
`engineer_id` INTEGER NOT NULL,
`fault_log_entry_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
`visit_start_datetime` DATETIME,
`visit_end_datetime` DATETIME,
`other_visit_details` VARCHAR(255),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` ),
FOREIGN KEY (`engineer_id` ) REFERENCES `Maintenance_Engineers`(`engineer_id` ),
FOREIGN KEY (`contact_staff_id` ) REFERENCES `Staff`(`staff_id` )
);
CREATE TABLE `Part_Faults` (
`part_fault_id` INTEGER PRIMARY KEY,
`part_id` INTEGER NOT NULL,
`fault_short_name` VARCHAR(20),
`fault_description` VARCHAR(255),
`other_fault_details` VARCHAR(255),
FOREIGN KEY (`part_id` ) REFERENCES `Parts`(`part_id` )
);
CREATE TABLE `Fault_Log_Parts` (
`fault_log_entry_id` INTEGER NOT NULL,
`part_fault_id` INTEGER NOT NULL,
`fault_status` VARCHAR(10) NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`fault_log_entry_id` ) REFERENCES `Fault_Log`(`fault_log_entry_id` )
);
CREATE TABLE `Skills_Required_To_Fix` (
`part_fault_id` INTEGER NOT NULL,
`skill_id` INTEGER NOT NULL,
FOREIGN KEY (`part_fault_id` ) REFERENCES `Part_Faults`(`part_fault_id` ),
FOREIGN KEY (`skill_id` ) REFERENCES `Skills`(`skill_id` )
);
INSERT INTO Third_Party_Companies (`company_id`, `company_type`, `company_name`, `company_address`, `other_company_details`) VALUES (1, 'Maintenance Contractor', 'Langworth-Funk', '615 Jacobs Mews', 'Uganda')INSERT INTO Maintenance_Contracts (`maintenance_contract_id`, `maintenance_contract_company_id`, `contract_start_date`, `contract_end_date`, `other_contract_details`) VALUES (1, 15, '2017-09-13 11:51:29', '2018-03-16 21:21:50', NULL)INSERT INTO Parts (`part_id`, `part_name`, `chargeable_yn`, `chargeable_amount`, `other_part_details`) VALUES (1, 'top', '0', '4', NULL)INSERT INTO Skills (`skill_id`, `skill_code`, `skill_description`) VALUES (1, 'ELEC', 'Electrical')INSERT INTO Staff (`staff_id`, `staff_name`, `gender`, `other_staff_details`) VALUES (1, 'Audreanne', '1', 'Manager')INSERT INTO Assets (`asset_id`, `maintenance_contract_id`, `supplier_company_id`, `asset_details`, `asset_make`, `asset_model`, `asset_acquired_date`, `asset_disposed_date`, `other_asset_details`) VALUES (1, 2, 2, 'dell laptop1', 'PT', '58 ub', '2017-12-25 00:31:27', '2018-03-14 10:50:00', NULL)INSERT INTO Asset_Parts (`asset_id`, `part_id`) VALUES (5, 3)INSERT INTO Maintenance_Engineers (`engineer_id`, `company_id`, `first_name`, `last_name`, `other_details`) VALUES (1, 14, 'Etha', 'Reinger', 'Skilled')INSERT INTO Engineer_Skills (`engineer_id`, `skill_id`) VALUES (10, 2)INSERT INTO Fault_Log (`fault_log_entry_id`, `asset_id`, `recorded_by_staff_id`, `fault_log_entry_datetime`, `fault_description`, `other_fault_details`) VALUES (1, 3, 14, '2018-03-21 04:25:00', 'system error', NULL)INSERT INTO Engineer_Visits (`engineer_visit_id`, `contact_staff_id`, `engineer_id`, `fault_log_entry_id`, `fault_status`, `visit_start_datetime`, `visit_end_datetime`, `other_visit_details`) VALUES (1, 8, 8, 13, 'Waiting', '1978-10-12 23:14:40', '1988-01-07 06:41:51', NULL)INSERT INTO Part_Faults (`part_fault_id`, `part_id`, `fault_short_name`, `fault_description`, `other_fault_details`) VALUES (1, 1, 'PW', 'Package Wrong', NULL)INSERT INTO Fault_Log_Parts (`fault_log_entry_id`, `part_fault_id`, `fault_status`) VALUES (12, 3, 'Reported')INSERT INTO Skills_Required_To_Fix (`part_fault_id`, `skill_id`) VALUES (3, 2) |
station_weather | SELECT local_authority , services FROM station | list the local authorities and services provided by all stations. | PRAGMA foreign_keys = ON;
CREATE TABLE "train" (
"id" int,
"train_number" int,
"name" text,
"origin" text,
"destination" text,
"time" text,
"interval" text,
primary key ("id")
);
CREATE TABLE "station" (
"id" int,
"network_name" text,
"services" text,
"local_authority" text,
primary key ("id")
);
CREATE TABLE "route" (
"train_id" int,
"station_id" int,
primary key ("train_id", "station_id"),
foreign key ("train_id") references `train`("id"),
foreign key ("station_id") references `station`("id")
);
CREATE TABLE "weekly_weather" (
"station_id" int,
"day_of_week" text,
"high_temperature" int,
"low_temperature" int,
"precipitation" real,
"wind_speed_mph" int,
primary key ("station_id", "day_of_week"),
foreign key ("station_id") references "station"("id")
);
INSERT INTO "train" VALUES ("1","16724","Ananthapuri Express","Trivandrum","Chennai","17:15","Daily");
INSERT INTO "station" VALUES (1, "Amersham","Metropolitan line and Chiltern Railways","Chiltern");
INSERT INTO "weekly_weather" VALUES (1, "Monday", 59, 54, "90", 13);
INSERT INTO "route" VALUES (1,1);
|
station_weather | SELECT train_number , name FROM train ORDER BY TIME | show all train numbers and names ordered by their time from early to late. | PRAGMA foreign_keys = ON;
CREATE TABLE "train" (
"id" int,
"train_number" int,
"name" text,
"origin" text,
"destination" text,
"time" text,
"interval" text,
primary key ("id")
);
CREATE TABLE "station" (
"id" int,
"network_name" text,
"services" text,
"local_authority" text,
primary key ("id")
);
CREATE TABLE "route" (
"train_id" int,
"station_id" int,
primary key ("train_id", "station_id"),
foreign key ("train_id") references `train`("id"),
foreign key ("station_id") references `station`("id")
);
CREATE TABLE "weekly_weather" (
"station_id" int,
"day_of_week" text,
"high_temperature" int,
"low_temperature" int,
"precipitation" real,
"wind_speed_mph" int,
primary key ("station_id", "day_of_week"),
foreign key ("station_id") references "station"("id")
);
INSERT INTO "train" VALUES ("1","16724","Ananthapuri Express","Trivandrum","Chennai","17:15","Daily");
INSERT INTO "station" VALUES (1, "Amersham","Metropolitan line and Chiltern Railways","Chiltern");
INSERT INTO "weekly_weather" VALUES (1, "Monday", 59, 54, "90", 13);
INSERT INTO "route" VALUES (1,1);
|
station_weather | SELECT TIME , train_number FROM train WHERE destination = 'Chennai' ORDER BY TIME | Give me the times and numbers of all trains that go to Chennai, ordered by time. | PRAGMA foreign_keys = ON;
CREATE TABLE "train" (
"id" int,
"train_number" int,
"name" text,
"origin" text,
"destination" text,
"time" text,
"interval" text,
primary key ("id")
);
CREATE TABLE "station" (
"id" int,
"network_name" text,
"services" text,
"local_authority" text,
primary key ("id")
);
CREATE TABLE "route" (
"train_id" int,
"station_id" int,
primary key ("train_id", "station_id"),
foreign key ("train_id") references `train`("id"),
foreign key ("station_id") references `station`("id")
);
CREATE TABLE "weekly_weather" (
"station_id" int,
"day_of_week" text,
"high_temperature" int,
"low_temperature" int,
"precipitation" real,
"wind_speed_mph" int,
primary key ("station_id", "day_of_week"),
foreign key ("station_id") references "station"("id")
);
INSERT INTO "train" VALUES ("1","16724","Ananthapuri Express","Trivandrum","Chennai","17:15","Daily");
INSERT INTO "station" VALUES (1, "Amersham","Metropolitan line and Chiltern Railways","Chiltern");
INSERT INTO "weekly_weather" VALUES (1, "Monday", 59, 54, "90", 13);
INSERT INTO "route" VALUES (1,1);
|
station_weather | SELECT count(*) FROM train WHERE name LIKE "%Express%" | How many trains have 'Express' in their names? | PRAGMA foreign_keys = ON;
CREATE TABLE "train" (
"id" int,
"train_number" int,
"name" text,
"origin" text,
"destination" text,
"time" text,
"interval" text,
primary key ("id")
);
CREATE TABLE "station" (
"id" int,
"network_name" text,
"services" text,
"local_authority" text,
primary key ("id")
);
CREATE TABLE "route" (
"train_id" int,
"station_id" int,
primary key ("train_id", "station_id"),
foreign key ("train_id") references `train`("id"),
foreign key ("station_id") references `station`("id")
);
CREATE TABLE "weekly_weather" (
"station_id" int,
"day_of_week" text,
"high_temperature" int,
"low_temperature" int,
"precipitation" real,
"wind_speed_mph" int,
primary key ("station_id", "day_of_week"),
foreign key ("station_id") references "station"("id")
);
INSERT INTO "train" VALUES ("1","16724","Ananthapuri Express","Trivandrum","Chennai","17:15","Daily");
INSERT INTO "station" VALUES (1, "Amersham","Metropolitan line and Chiltern Railways","Chiltern");
INSERT INTO "weekly_weather" VALUES (1, "Monday", 59, 54, "90", 13);
INSERT INTO "route" VALUES (1,1);
|
station_weather | SELECT train_number , TIME FROM train WHERE origin = 'Chennai' AND destination = 'Guruvayur' | Find the number and time of the train that goes from Chennai to Guruvayur. | PRAGMA foreign_keys = ON;
CREATE TABLE "train" (
"id" int,
"train_number" int,
"name" text,
"origin" text,
"destination" text,
"time" text,
"interval" text,
primary key ("id")
);
CREATE TABLE "station" (
"id" int,
"network_name" text,
"services" text,
"local_authority" text,
primary key ("id")
);
CREATE TABLE "route" (
"train_id" int,
"station_id" int,
primary key ("train_id", "station_id"),
foreign key ("train_id") references `train`("id"),
foreign key ("station_id") references `station`("id")
);
CREATE TABLE "weekly_weather" (
"station_id" int,
"day_of_week" text,
"high_temperature" int,
"low_temperature" int,
"precipitation" real,
"wind_speed_mph" int,
primary key ("station_id", "day_of_week"),
foreign key ("station_id") references "station"("id")
);
INSERT INTO "train" VALUES ("1","16724","Ananthapuri Express","Trivandrum","Chennai","17:15","Daily");
INSERT INTO "station" VALUES (1, "Amersham","Metropolitan line and Chiltern Railways","Chiltern");
INSERT INTO "weekly_weather" VALUES (1, "Monday", 59, 54, "90", 13);
INSERT INTO "route" VALUES (1,1);
|
station_weather | SELECT origin , count(*) FROM train GROUP BY origin | Find the number of trains starting from each origin. | PRAGMA foreign_keys = ON;
CREATE TABLE "train" (
"id" int,
"train_number" int,
"name" text,
"origin" text,
"destination" text,
"time" text,
"interval" text,
primary key ("id")
);
CREATE TABLE "station" (
"id" int,
"network_name" text,
"services" text,
"local_authority" text,
primary key ("id")
);
CREATE TABLE "route" (
"train_id" int,
"station_id" int,
primary key ("train_id", "station_id"),
foreign key ("train_id") references `train`("id"),
foreign key ("station_id") references `station`("id")
);
CREATE TABLE "weekly_weather" (
"station_id" int,
"day_of_week" text,
"high_temperature" int,
"low_temperature" int,
"precipitation" real,
"wind_speed_mph" int,
primary key ("station_id", "day_of_week"),
foreign key ("station_id") references "station"("id")
);
INSERT INTO "train" VALUES ("1","16724","Ananthapuri Express","Trivandrum","Chennai","17:15","Daily");
INSERT INTO "station" VALUES (1, "Amersham","Metropolitan line and Chiltern Railways","Chiltern");
INSERT INTO "weekly_weather" VALUES (1, "Monday", 59, 54, "90", 13);
INSERT INTO "route" VALUES (1,1);
|
station_weather | SELECT t1.name FROM train AS t1 JOIN route AS t2 ON t1.id = t2.train_id GROUP BY t2.train_id ORDER BY count(*) DESC LIMIT 1 | Find the name of the train whose route runs through greatest number of stations. | PRAGMA foreign_keys = ON;
CREATE TABLE "train" (
"id" int,
"train_number" int,
"name" text,
"origin" text,
"destination" text,
"time" text,
"interval" text,
primary key ("id")
);
CREATE TABLE "station" (
"id" int,
"network_name" text,
"services" text,
"local_authority" text,
primary key ("id")
);
CREATE TABLE "route" (
"train_id" int,
"station_id" int,
primary key ("train_id", "station_id"),
foreign key ("train_id") references `train`("id"),
foreign key ("station_id") references `station`("id")
);
CREATE TABLE "weekly_weather" (
"station_id" int,
"day_of_week" text,
"high_temperature" int,
"low_temperature" int,
"precipitation" real,
"wind_speed_mph" int,
primary key ("station_id", "day_of_week"),
foreign key ("station_id") references "station"("id")
);
INSERT INTO "train" VALUES ("1","16724","Ananthapuri Express","Trivandrum","Chennai","17:15","Daily");
INSERT INTO "station" VALUES (1, "Amersham","Metropolitan line and Chiltern Railways","Chiltern");
INSERT INTO "weekly_weather" VALUES (1, "Monday", 59, 54, "90", 13);
INSERT INTO "route" VALUES (1,1);
|
station_weather | SELECT count(*) , t1.network_name , t1.services FROM station AS t1 JOIN route AS t2 ON t1.id = t2.station_id GROUP BY t2.station_id | Find the number of trains for each station, as well as the station network name and services. | PRAGMA foreign_keys = ON;
CREATE TABLE "train" (
"id" int,
"train_number" int,
"name" text,
"origin" text,
"destination" text,
"time" text,
"interval" text,
primary key ("id")
);
CREATE TABLE "station" (
"id" int,
"network_name" text,
"services" text,
"local_authority" text,
primary key ("id")
);
CREATE TABLE "route" (
"train_id" int,
"station_id" int,
primary key ("train_id", "station_id"),
foreign key ("train_id") references `train`("id"),
foreign key ("station_id") references `station`("id")
);
CREATE TABLE "weekly_weather" (
"station_id" int,
"day_of_week" text,
"high_temperature" int,
"low_temperature" int,
"precipitation" real,
"wind_speed_mph" int,
primary key ("station_id", "day_of_week"),
foreign key ("station_id") references "station"("id")
);
INSERT INTO "train" VALUES ("1","16724","Ananthapuri Express","Trivandrum","Chennai","17:15","Daily");
INSERT INTO "station" VALUES (1, "Amersham","Metropolitan line and Chiltern Railways","Chiltern");
INSERT INTO "weekly_weather" VALUES (1, "Monday", 59, 54, "90", 13);
INSERT INTO "route" VALUES (1,1);
|
station_weather | SELECT avg(high_temperature) , day_of_week FROM weekly_weather GROUP BY day_of_week | What is the average high temperature for each day of week? | PRAGMA foreign_keys = ON;
CREATE TABLE "train" (
"id" int,
"train_number" int,
"name" text,
"origin" text,
"destination" text,
"time" text,
"interval" text,
primary key ("id")
);
CREATE TABLE "station" (
"id" int,
"network_name" text,
"services" text,
"local_authority" text,
primary key ("id")
);
CREATE TABLE "route" (
"train_id" int,
"station_id" int,
primary key ("train_id", "station_id"),
foreign key ("train_id") references `train`("id"),
foreign key ("station_id") references `station`("id")
);
CREATE TABLE "weekly_weather" (
"station_id" int,
"day_of_week" text,
"high_temperature" int,
"low_temperature" int,
"precipitation" real,
"wind_speed_mph" int,
primary key ("station_id", "day_of_week"),
foreign key ("station_id") references "station"("id")
);
INSERT INTO "train" VALUES ("1","16724","Ananthapuri Express","Trivandrum","Chennai","17:15","Daily");
INSERT INTO "station" VALUES (1, "Amersham","Metropolitan line and Chiltern Railways","Chiltern");
INSERT INTO "weekly_weather" VALUES (1, "Monday", 59, 54, "90", 13);
INSERT INTO "route" VALUES (1,1);
|
station_weather | SELECT max(t1.low_temperature) , avg(t1.precipitation) FROM weekly_weather AS t1 JOIN station AS t2 ON t1.station_id = t2.id WHERE t2.network_name = "Amersham" | Give me the maximum low temperature and average precipitation at the Amersham station. | PRAGMA foreign_keys = ON;
CREATE TABLE "train" (
"id" int,
"train_number" int,
"name" text,
"origin" text,
"destination" text,
"time" text,
"interval" text,
primary key ("id")
);
CREATE TABLE "station" (
"id" int,
"network_name" text,
"services" text,
"local_authority" text,
primary key ("id")
);
CREATE TABLE "route" (
"train_id" int,
"station_id" int,
primary key ("train_id", "station_id"),
foreign key ("train_id") references `train`("id"),
foreign key ("station_id") references `station`("id")
);
CREATE TABLE "weekly_weather" (
"station_id" int,
"day_of_week" text,
"high_temperature" int,
"low_temperature" int,
"precipitation" real,
"wind_speed_mph" int,
primary key ("station_id", "day_of_week"),
foreign key ("station_id") references "station"("id")
);
INSERT INTO "train" VALUES ("1","16724","Ananthapuri Express","Trivandrum","Chennai","17:15","Daily");
INSERT INTO "station" VALUES (1, "Amersham","Metropolitan line and Chiltern Railways","Chiltern");
INSERT INTO "weekly_weather" VALUES (1, "Monday", 59, 54, "90", 13);
INSERT INTO "route" VALUES (1,1);
|
station_weather | SELECT t3.name , t3.time FROM station AS t1 JOIN route AS t2 ON t1.id = t2.station_id JOIN train AS t3 ON t2.train_id = t3.id WHERE t1.local_authority = "Chiltern" | Find names and times of trains that run through stations for the local authority Chiltern. | PRAGMA foreign_keys = ON;
CREATE TABLE "train" (
"id" int,
"train_number" int,
"name" text,
"origin" text,
"destination" text,
"time" text,
"interval" text,
primary key ("id")
);
CREATE TABLE "station" (
"id" int,
"network_name" text,
"services" text,
"local_authority" text,
primary key ("id")
);
CREATE TABLE "route" (
"train_id" int,
"station_id" int,
primary key ("train_id", "station_id"),
foreign key ("train_id") references `train`("id"),
foreign key ("station_id") references `station`("id")
);
CREATE TABLE "weekly_weather" (
"station_id" int,
"day_of_week" text,
"high_temperature" int,
"low_temperature" int,
"precipitation" real,
"wind_speed_mph" int,
primary key ("station_id", "day_of_week"),
foreign key ("station_id") references "station"("id")
);
INSERT INTO "train" VALUES ("1","16724","Ananthapuri Express","Trivandrum","Chennai","17:15","Daily");
INSERT INTO "station" VALUES (1, "Amersham","Metropolitan line and Chiltern Railways","Chiltern");
INSERT INTO "weekly_weather" VALUES (1, "Monday", 59, 54, "90", 13);
INSERT INTO "route" VALUES (1,1);
|
station_weather | SELECT count(DISTINCT services) FROM station | How many different services are provided by all stations? | PRAGMA foreign_keys = ON;
CREATE TABLE "train" (
"id" int,
"train_number" int,
"name" text,
"origin" text,
"destination" text,
"time" text,
"interval" text,
primary key ("id")
);
CREATE TABLE "station" (
"id" int,
"network_name" text,
"services" text,
"local_authority" text,
primary key ("id")
);
CREATE TABLE "route" (
"train_id" int,
"station_id" int,
primary key ("train_id", "station_id"),
foreign key ("train_id") references `train`("id"),
foreign key ("station_id") references `station`("id")
);
CREATE TABLE "weekly_weather" (
"station_id" int,
"day_of_week" text,
"high_temperature" int,
"low_temperature" int,
"precipitation" real,
"wind_speed_mph" int,
primary key ("station_id", "day_of_week"),
foreign key ("station_id") references "station"("id")
);
INSERT INTO "train" VALUES ("1","16724","Ananthapuri Express","Trivandrum","Chennai","17:15","Daily");
INSERT INTO "station" VALUES (1, "Amersham","Metropolitan line and Chiltern Railways","Chiltern");
INSERT INTO "weekly_weather" VALUES (1, "Monday", 59, 54, "90", 13);
INSERT INTO "route" VALUES (1,1);
|
station_weather | SELECT t2.id , t2.local_authority FROM weekly_weather AS t1 JOIN station AS t2 ON t1.station_id = t2.id GROUP BY t1.station_id ORDER BY avg(high_temperature) DESC LIMIT 1 | Find the id and local authority of the station with has the highest average high temperature. | PRAGMA foreign_keys = ON;
CREATE TABLE "train" (
"id" int,
"train_number" int,
"name" text,
"origin" text,
"destination" text,
"time" text,
"interval" text,
primary key ("id")
);
CREATE TABLE "station" (
"id" int,
"network_name" text,
"services" text,
"local_authority" text,
primary key ("id")
);
CREATE TABLE "route" (
"train_id" int,
"station_id" int,
primary key ("train_id", "station_id"),
foreign key ("train_id") references `train`("id"),
foreign key ("station_id") references `station`("id")
);
CREATE TABLE "weekly_weather" (
"station_id" int,
"day_of_week" text,
"high_temperature" int,
"low_temperature" int,
"precipitation" real,
"wind_speed_mph" int,
primary key ("station_id", "day_of_week"),
foreign key ("station_id") references "station"("id")
);
INSERT INTO "train" VALUES ("1","16724","Ananthapuri Express","Trivandrum","Chennai","17:15","Daily");
INSERT INTO "station" VALUES (1, "Amersham","Metropolitan line and Chiltern Railways","Chiltern");
INSERT INTO "weekly_weather" VALUES (1, "Monday", 59, 54, "90", 13);
INSERT INTO "route" VALUES (1,1);
|
station_weather | SELECT t2.id , t2.local_authority FROM weekly_weather AS t1 JOIN station AS t2 ON t1.station_id = t2.id GROUP BY t1.station_id HAVING max(t1.precipitation) > 50 | Find the id and local authority of the station whose maximum precipitation is higher than 50. | PRAGMA foreign_keys = ON;
CREATE TABLE "train" (
"id" int,
"train_number" int,
"name" text,
"origin" text,
"destination" text,
"time" text,
"interval" text,
primary key ("id")
);
CREATE TABLE "station" (
"id" int,
"network_name" text,
"services" text,
"local_authority" text,
primary key ("id")
);
CREATE TABLE "route" (
"train_id" int,
"station_id" int,
primary key ("train_id", "station_id"),
foreign key ("train_id") references `train`("id"),
foreign key ("station_id") references `station`("id")
);
CREATE TABLE "weekly_weather" (
"station_id" int,
"day_of_week" text,
"high_temperature" int,
"low_temperature" int,
"precipitation" real,
"wind_speed_mph" int,
primary key ("station_id", "day_of_week"),
foreign key ("station_id") references "station"("id")
);
INSERT INTO "train" VALUES ("1","16724","Ananthapuri Express","Trivandrum","Chennai","17:15","Daily");
INSERT INTO "station" VALUES (1, "Amersham","Metropolitan line and Chiltern Railways","Chiltern");
INSERT INTO "weekly_weather" VALUES (1, "Monday", 59, 54, "90", 13);
INSERT INTO "route" VALUES (1,1);
|
station_weather | SELECT min(low_temperature) , max(wind_speed_mph) FROM weekly_weather | show the lowest low temperature and highest wind speed in miles per hour. | PRAGMA foreign_keys = ON;
CREATE TABLE "train" (
"id" int,
"train_number" int,
"name" text,
"origin" text,
"destination" text,
"time" text,
"interval" text,
primary key ("id")
);
CREATE TABLE "station" (
"id" int,
"network_name" text,
"services" text,
"local_authority" text,
primary key ("id")
);
CREATE TABLE "route" (
"train_id" int,
"station_id" int,
primary key ("train_id", "station_id"),
foreign key ("train_id") references `train`("id"),
foreign key ("station_id") references `station`("id")
);
CREATE TABLE "weekly_weather" (
"station_id" int,
"day_of_week" text,
"high_temperature" int,
"low_temperature" int,
"precipitation" real,
"wind_speed_mph" int,
primary key ("station_id", "day_of_week"),
foreign key ("station_id") references "station"("id")
);
INSERT INTO "train" VALUES ("1","16724","Ananthapuri Express","Trivandrum","Chennai","17:15","Daily");
INSERT INTO "station" VALUES (1, "Amersham","Metropolitan line and Chiltern Railways","Chiltern");
INSERT INTO "weekly_weather" VALUES (1, "Monday", 59, 54, "90", 13);
INSERT INTO "route" VALUES (1,1);
|
station_weather | SELECT origin FROM train GROUP BY origin HAVING count(*) > 1 | Find the origins from which more than 1 train starts. | PRAGMA foreign_keys = ON;
CREATE TABLE "train" (
"id" int,
"train_number" int,
"name" text,
"origin" text,
"destination" text,
"time" text,
"interval" text,
primary key ("id")
);
CREATE TABLE "station" (
"id" int,
"network_name" text,
"services" text,
"local_authority" text,
primary key ("id")
);
CREATE TABLE "route" (
"train_id" int,
"station_id" int,
primary key ("train_id", "station_id"),
foreign key ("train_id") references `train`("id"),
foreign key ("station_id") references `station`("id")
);
CREATE TABLE "weekly_weather" (
"station_id" int,
"day_of_week" text,
"high_temperature" int,
"low_temperature" int,
"precipitation" real,
"wind_speed_mph" int,
primary key ("station_id", "day_of_week"),
foreign key ("station_id") references "station"("id")
);
INSERT INTO "train" VALUES ("1","16724","Ananthapuri Express","Trivandrum","Chennai","17:15","Daily");
INSERT INTO "station" VALUES (1, "Amersham","Metropolitan line and Chiltern Railways","Chiltern");
INSERT INTO "weekly_weather" VALUES (1, "Monday", 59, 54, "90", 13);
INSERT INTO "route" VALUES (1,1);
|
sports_competition | SELECT count(*) FROM club | How many clubs are there? |
PRAGMA foreign_keys = ON;
CREATE TABLE "club" (
"Club_ID" int,
"name" text,
"Region" text,
"Start_year" text,
PRIMARY KEY ("Club_ID")
);
CREATE TABLE "club_rank" (
"Rank" real,
"Club_ID" int,
"Gold" real,
"Silver" real,
"Bronze" real,
"Total" real,
PRIMARY KEY ("Rank","Club_ID")
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "player" (
"Player_ID" int,
"name" text,
"Position" text,
"Club_ID" int,
"Apps" real,
"Tries" real,
"Goals" text,
"Points" real,
PRIMARY KEY ("Player_ID"),
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "competition" (
"Competition_ID" int,
"Year" real,
"Competition_type" text,
"Country" text,
PRIMARY KEY ("Competition_ID")
);
CREATE TABLE "competition_result" (
"Competition_ID" int,
"Club_ID_1" int,
"Club_ID_2" int,
"Score" text,
PRIMARY KEY ("Competition_ID","Club_ID_1","Club_ID_2"),
FOREIGN KEY (`Club_ID_1`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Club_ID_2`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Competition_ID`) REFERENCES `competition`(`Competition_ID`)
);
INSERT INTO "club" VALUES (1,"AIB","USA","2009");
INSERT INTO "club_rank" VALUES ("1",2,"11","11","9","31");
INSERT INTO "player" VALUES (1,"Michael Platt","Full Back",1,"20","5","0","20");
INSERT INTO "competition" VALUES (1,"2006","Friendly","Italy");
INSERT INTO "competition_result" VALUES (1,1,2,"11:10");
|
sports_competition | SELECT count(*) FROM club | What is the total number of clubs? |
PRAGMA foreign_keys = ON;
CREATE TABLE "club" (
"Club_ID" int,
"name" text,
"Region" text,
"Start_year" text,
PRIMARY KEY ("Club_ID")
);
CREATE TABLE "club_rank" (
"Rank" real,
"Club_ID" int,
"Gold" real,
"Silver" real,
"Bronze" real,
"Total" real,
PRIMARY KEY ("Rank","Club_ID")
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "player" (
"Player_ID" int,
"name" text,
"Position" text,
"Club_ID" int,
"Apps" real,
"Tries" real,
"Goals" text,
"Points" real,
PRIMARY KEY ("Player_ID"),
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "competition" (
"Competition_ID" int,
"Year" real,
"Competition_type" text,
"Country" text,
PRIMARY KEY ("Competition_ID")
);
CREATE TABLE "competition_result" (
"Competition_ID" int,
"Club_ID_1" int,
"Club_ID_2" int,
"Score" text,
PRIMARY KEY ("Competition_ID","Club_ID_1","Club_ID_2"),
FOREIGN KEY (`Club_ID_1`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Club_ID_2`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Competition_ID`) REFERENCES `competition`(`Competition_ID`)
);
INSERT INTO "club" VALUES (1,"AIB","USA","2009");
INSERT INTO "club_rank" VALUES ("1",2,"11","11","9","31");
INSERT INTO "player" VALUES (1,"Michael Platt","Full Back",1,"20","5","0","20");
INSERT INTO "competition" VALUES (1,"2006","Friendly","Italy");
INSERT INTO "competition_result" VALUES (1,1,2,"11:10");
|
sports_competition | SELECT DISTINCT Region FROM club ORDER BY Region ASC | List the distinct region of clubs in ascending alphabetical order. |
PRAGMA foreign_keys = ON;
CREATE TABLE "club" (
"Club_ID" int,
"name" text,
"Region" text,
"Start_year" text,
PRIMARY KEY ("Club_ID")
);
CREATE TABLE "club_rank" (
"Rank" real,
"Club_ID" int,
"Gold" real,
"Silver" real,
"Bronze" real,
"Total" real,
PRIMARY KEY ("Rank","Club_ID")
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "player" (
"Player_ID" int,
"name" text,
"Position" text,
"Club_ID" int,
"Apps" real,
"Tries" real,
"Goals" text,
"Points" real,
PRIMARY KEY ("Player_ID"),
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "competition" (
"Competition_ID" int,
"Year" real,
"Competition_type" text,
"Country" text,
PRIMARY KEY ("Competition_ID")
);
CREATE TABLE "competition_result" (
"Competition_ID" int,
"Club_ID_1" int,
"Club_ID_2" int,
"Score" text,
PRIMARY KEY ("Competition_ID","Club_ID_1","Club_ID_2"),
FOREIGN KEY (`Club_ID_1`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Club_ID_2`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Competition_ID`) REFERENCES `competition`(`Competition_ID`)
);
INSERT INTO "club" VALUES (1,"AIB","USA","2009");
INSERT INTO "club_rank" VALUES ("1",2,"11","11","9","31");
INSERT INTO "player" VALUES (1,"Michael Platt","Full Back",1,"20","5","0","20");
INSERT INTO "competition" VALUES (1,"2006","Friendly","Italy");
INSERT INTO "competition_result" VALUES (1,1,2,"11:10");
|
sports_competition | SELECT DISTINCT Region FROM club ORDER BY Region ASC | What are the different regions of clubs in ascending alphabetical order? |
PRAGMA foreign_keys = ON;
CREATE TABLE "club" (
"Club_ID" int,
"name" text,
"Region" text,
"Start_year" text,
PRIMARY KEY ("Club_ID")
);
CREATE TABLE "club_rank" (
"Rank" real,
"Club_ID" int,
"Gold" real,
"Silver" real,
"Bronze" real,
"Total" real,
PRIMARY KEY ("Rank","Club_ID")
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "player" (
"Player_ID" int,
"name" text,
"Position" text,
"Club_ID" int,
"Apps" real,
"Tries" real,
"Goals" text,
"Points" real,
PRIMARY KEY ("Player_ID"),
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "competition" (
"Competition_ID" int,
"Year" real,
"Competition_type" text,
"Country" text,
PRIMARY KEY ("Competition_ID")
);
CREATE TABLE "competition_result" (
"Competition_ID" int,
"Club_ID_1" int,
"Club_ID_2" int,
"Score" text,
PRIMARY KEY ("Competition_ID","Club_ID_1","Club_ID_2"),
FOREIGN KEY (`Club_ID_1`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Club_ID_2`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Competition_ID`) REFERENCES `competition`(`Competition_ID`)
);
INSERT INTO "club" VALUES (1,"AIB","USA","2009");
INSERT INTO "club_rank" VALUES ("1",2,"11","11","9","31");
INSERT INTO "player" VALUES (1,"Michael Platt","Full Back",1,"20","5","0","20");
INSERT INTO "competition" VALUES (1,"2006","Friendly","Italy");
INSERT INTO "competition_result" VALUES (1,1,2,"11:10");
|
sports_competition | SELECT avg(Gold) FROM club_rank | What is the average number of gold medals for clubs? |
PRAGMA foreign_keys = ON;
CREATE TABLE "club" (
"Club_ID" int,
"name" text,
"Region" text,
"Start_year" text,
PRIMARY KEY ("Club_ID")
);
CREATE TABLE "club_rank" (
"Rank" real,
"Club_ID" int,
"Gold" real,
"Silver" real,
"Bronze" real,
"Total" real,
PRIMARY KEY ("Rank","Club_ID")
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "player" (
"Player_ID" int,
"name" text,
"Position" text,
"Club_ID" int,
"Apps" real,
"Tries" real,
"Goals" text,
"Points" real,
PRIMARY KEY ("Player_ID"),
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "competition" (
"Competition_ID" int,
"Year" real,
"Competition_type" text,
"Country" text,
PRIMARY KEY ("Competition_ID")
);
CREATE TABLE "competition_result" (
"Competition_ID" int,
"Club_ID_1" int,
"Club_ID_2" int,
"Score" text,
PRIMARY KEY ("Competition_ID","Club_ID_1","Club_ID_2"),
FOREIGN KEY (`Club_ID_1`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Club_ID_2`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Competition_ID`) REFERENCES `competition`(`Competition_ID`)
);
INSERT INTO "club" VALUES (1,"AIB","USA","2009");
INSERT INTO "club_rank" VALUES ("1",2,"11","11","9","31");
INSERT INTO "player" VALUES (1,"Michael Platt","Full Back",1,"20","5","0","20");
INSERT INTO "competition" VALUES (1,"2006","Friendly","Italy");
INSERT INTO "competition_result" VALUES (1,1,2,"11:10");
|
sports_competition | SELECT avg(Gold) FROM club_rank | What is the average number of gold medals for a club? |
PRAGMA foreign_keys = ON;
CREATE TABLE "club" (
"Club_ID" int,
"name" text,
"Region" text,
"Start_year" text,
PRIMARY KEY ("Club_ID")
);
CREATE TABLE "club_rank" (
"Rank" real,
"Club_ID" int,
"Gold" real,
"Silver" real,
"Bronze" real,
"Total" real,
PRIMARY KEY ("Rank","Club_ID")
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "player" (
"Player_ID" int,
"name" text,
"Position" text,
"Club_ID" int,
"Apps" real,
"Tries" real,
"Goals" text,
"Points" real,
PRIMARY KEY ("Player_ID"),
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "competition" (
"Competition_ID" int,
"Year" real,
"Competition_type" text,
"Country" text,
PRIMARY KEY ("Competition_ID")
);
CREATE TABLE "competition_result" (
"Competition_ID" int,
"Club_ID_1" int,
"Club_ID_2" int,
"Score" text,
PRIMARY KEY ("Competition_ID","Club_ID_1","Club_ID_2"),
FOREIGN KEY (`Club_ID_1`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Club_ID_2`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Competition_ID`) REFERENCES `competition`(`Competition_ID`)
);
INSERT INTO "club" VALUES (1,"AIB","USA","2009");
INSERT INTO "club_rank" VALUES ("1",2,"11","11","9","31");
INSERT INTO "player" VALUES (1,"Michael Platt","Full Back",1,"20","5","0","20");
INSERT INTO "competition" VALUES (1,"2006","Friendly","Italy");
INSERT INTO "competition_result" VALUES (1,1,2,"11:10");
|
sports_competition | SELECT Competition_type , Country FROM competition | What are the types and countries of competitions? |
PRAGMA foreign_keys = ON;
CREATE TABLE "club" (
"Club_ID" int,
"name" text,
"Region" text,
"Start_year" text,
PRIMARY KEY ("Club_ID")
);
CREATE TABLE "club_rank" (
"Rank" real,
"Club_ID" int,
"Gold" real,
"Silver" real,
"Bronze" real,
"Total" real,
PRIMARY KEY ("Rank","Club_ID")
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "player" (
"Player_ID" int,
"name" text,
"Position" text,
"Club_ID" int,
"Apps" real,
"Tries" real,
"Goals" text,
"Points" real,
PRIMARY KEY ("Player_ID"),
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "competition" (
"Competition_ID" int,
"Year" real,
"Competition_type" text,
"Country" text,
PRIMARY KEY ("Competition_ID")
);
CREATE TABLE "competition_result" (
"Competition_ID" int,
"Club_ID_1" int,
"Club_ID_2" int,
"Score" text,
PRIMARY KEY ("Competition_ID","Club_ID_1","Club_ID_2"),
FOREIGN KEY (`Club_ID_1`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Club_ID_2`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Competition_ID`) REFERENCES `competition`(`Competition_ID`)
);
INSERT INTO "club" VALUES (1,"AIB","USA","2009");
INSERT INTO "club_rank" VALUES ("1",2,"11","11","9","31");
INSERT INTO "player" VALUES (1,"Michael Platt","Full Back",1,"20","5","0","20");
INSERT INTO "competition" VALUES (1,"2006","Friendly","Italy");
INSERT INTO "competition_result" VALUES (1,1,2,"11:10");
|
sports_competition | SELECT Competition_type , Country FROM competition | What are the types of every competition and in which countries are they located? |
PRAGMA foreign_keys = ON;
CREATE TABLE "club" (
"Club_ID" int,
"name" text,
"Region" text,
"Start_year" text,
PRIMARY KEY ("Club_ID")
);
CREATE TABLE "club_rank" (
"Rank" real,
"Club_ID" int,
"Gold" real,
"Silver" real,
"Bronze" real,
"Total" real,
PRIMARY KEY ("Rank","Club_ID")
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "player" (
"Player_ID" int,
"name" text,
"Position" text,
"Club_ID" int,
"Apps" real,
"Tries" real,
"Goals" text,
"Points" real,
PRIMARY KEY ("Player_ID"),
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "competition" (
"Competition_ID" int,
"Year" real,
"Competition_type" text,
"Country" text,
PRIMARY KEY ("Competition_ID")
);
CREATE TABLE "competition_result" (
"Competition_ID" int,
"Club_ID_1" int,
"Club_ID_2" int,
"Score" text,
PRIMARY KEY ("Competition_ID","Club_ID_1","Club_ID_2"),
FOREIGN KEY (`Club_ID_1`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Club_ID_2`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Competition_ID`) REFERENCES `competition`(`Competition_ID`)
);
INSERT INTO "club" VALUES (1,"AIB","USA","2009");
INSERT INTO "club_rank" VALUES ("1",2,"11","11","9","31");
INSERT INTO "player" VALUES (1,"Michael Platt","Full Back",1,"20","5","0","20");
INSERT INTO "competition" VALUES (1,"2006","Friendly","Italy");
INSERT INTO "competition_result" VALUES (1,1,2,"11:10");
|
sports_competition | SELECT DISTINCT YEAR FROM competition WHERE Competition_type != "Tournament" | What are the distinct years in which the competitions type is not "Tournament"? |
PRAGMA foreign_keys = ON;
CREATE TABLE "club" (
"Club_ID" int,
"name" text,
"Region" text,
"Start_year" text,
PRIMARY KEY ("Club_ID")
);
CREATE TABLE "club_rank" (
"Rank" real,
"Club_ID" int,
"Gold" real,
"Silver" real,
"Bronze" real,
"Total" real,
PRIMARY KEY ("Rank","Club_ID")
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "player" (
"Player_ID" int,
"name" text,
"Position" text,
"Club_ID" int,
"Apps" real,
"Tries" real,
"Goals" text,
"Points" real,
PRIMARY KEY ("Player_ID"),
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "competition" (
"Competition_ID" int,
"Year" real,
"Competition_type" text,
"Country" text,
PRIMARY KEY ("Competition_ID")
);
CREATE TABLE "competition_result" (
"Competition_ID" int,
"Club_ID_1" int,
"Club_ID_2" int,
"Score" text,
PRIMARY KEY ("Competition_ID","Club_ID_1","Club_ID_2"),
FOREIGN KEY (`Club_ID_1`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Club_ID_2`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Competition_ID`) REFERENCES `competition`(`Competition_ID`)
);
INSERT INTO "club" VALUES (1,"AIB","USA","2009");
INSERT INTO "club_rank" VALUES ("1",2,"11","11","9","31");
INSERT INTO "player" VALUES (1,"Michael Platt","Full Back",1,"20","5","0","20");
INSERT INTO "competition" VALUES (1,"2006","Friendly","Italy");
INSERT INTO "competition_result" VALUES (1,1,2,"11:10");
|
sports_competition | SELECT DISTINCT YEAR FROM competition WHERE Competition_type != "Tournament" | What are the different years for all competitions that are not of type equal to tournament? |
PRAGMA foreign_keys = ON;
CREATE TABLE "club" (
"Club_ID" int,
"name" text,
"Region" text,
"Start_year" text,
PRIMARY KEY ("Club_ID")
);
CREATE TABLE "club_rank" (
"Rank" real,
"Club_ID" int,
"Gold" real,
"Silver" real,
"Bronze" real,
"Total" real,
PRIMARY KEY ("Rank","Club_ID")
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "player" (
"Player_ID" int,
"name" text,
"Position" text,
"Club_ID" int,
"Apps" real,
"Tries" real,
"Goals" text,
"Points" real,
PRIMARY KEY ("Player_ID"),
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "competition" (
"Competition_ID" int,
"Year" real,
"Competition_type" text,
"Country" text,
PRIMARY KEY ("Competition_ID")
);
CREATE TABLE "competition_result" (
"Competition_ID" int,
"Club_ID_1" int,
"Club_ID_2" int,
"Score" text,
PRIMARY KEY ("Competition_ID","Club_ID_1","Club_ID_2"),
FOREIGN KEY (`Club_ID_1`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Club_ID_2`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Competition_ID`) REFERENCES `competition`(`Competition_ID`)
);
INSERT INTO "club" VALUES (1,"AIB","USA","2009");
INSERT INTO "club_rank" VALUES ("1",2,"11","11","9","31");
INSERT INTO "player" VALUES (1,"Michael Platt","Full Back",1,"20","5","0","20");
INSERT INTO "competition" VALUES (1,"2006","Friendly","Italy");
INSERT INTO "competition_result" VALUES (1,1,2,"11:10");
|
sports_competition | SELECT max(Silver) , min(Silver) FROM club_rank | What are the maximum and minimum number of silver medals for clubs. |
PRAGMA foreign_keys = ON;
CREATE TABLE "club" (
"Club_ID" int,
"name" text,
"Region" text,
"Start_year" text,
PRIMARY KEY ("Club_ID")
);
CREATE TABLE "club_rank" (
"Rank" real,
"Club_ID" int,
"Gold" real,
"Silver" real,
"Bronze" real,
"Total" real,
PRIMARY KEY ("Rank","Club_ID")
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "player" (
"Player_ID" int,
"name" text,
"Position" text,
"Club_ID" int,
"Apps" real,
"Tries" real,
"Goals" text,
"Points" real,
PRIMARY KEY ("Player_ID"),
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "competition" (
"Competition_ID" int,
"Year" real,
"Competition_type" text,
"Country" text,
PRIMARY KEY ("Competition_ID")
);
CREATE TABLE "competition_result" (
"Competition_ID" int,
"Club_ID_1" int,
"Club_ID_2" int,
"Score" text,
PRIMARY KEY ("Competition_ID","Club_ID_1","Club_ID_2"),
FOREIGN KEY (`Club_ID_1`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Club_ID_2`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Competition_ID`) REFERENCES `competition`(`Competition_ID`)
);
INSERT INTO "club" VALUES (1,"AIB","USA","2009");
INSERT INTO "club_rank" VALUES ("1",2,"11","11","9","31");
INSERT INTO "player" VALUES (1,"Michael Platt","Full Back",1,"20","5","0","20");
INSERT INTO "competition" VALUES (1,"2006","Friendly","Italy");
INSERT INTO "competition_result" VALUES (1,1,2,"11:10");
|
sports_competition | SELECT max(Silver) , min(Silver) FROM club_rank | What are the maximum and minimum number of silver medals for all the clubs? |
PRAGMA foreign_keys = ON;
CREATE TABLE "club" (
"Club_ID" int,
"name" text,
"Region" text,
"Start_year" text,
PRIMARY KEY ("Club_ID")
);
CREATE TABLE "club_rank" (
"Rank" real,
"Club_ID" int,
"Gold" real,
"Silver" real,
"Bronze" real,
"Total" real,
PRIMARY KEY ("Rank","Club_ID")
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "player" (
"Player_ID" int,
"name" text,
"Position" text,
"Club_ID" int,
"Apps" real,
"Tries" real,
"Goals" text,
"Points" real,
PRIMARY KEY ("Player_ID"),
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "competition" (
"Competition_ID" int,
"Year" real,
"Competition_type" text,
"Country" text,
PRIMARY KEY ("Competition_ID")
);
CREATE TABLE "competition_result" (
"Competition_ID" int,
"Club_ID_1" int,
"Club_ID_2" int,
"Score" text,
PRIMARY KEY ("Competition_ID","Club_ID_1","Club_ID_2"),
FOREIGN KEY (`Club_ID_1`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Club_ID_2`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Competition_ID`) REFERENCES `competition`(`Competition_ID`)
);
INSERT INTO "club" VALUES (1,"AIB","USA","2009");
INSERT INTO "club_rank" VALUES ("1",2,"11","11","9","31");
INSERT INTO "player" VALUES (1,"Michael Platt","Full Back",1,"20","5","0","20");
INSERT INTO "competition" VALUES (1,"2006","Friendly","Italy");
INSERT INTO "competition_result" VALUES (1,1,2,"11:10");
|
sports_competition | SELECT count(*) FROM club_rank WHERE Total < 10 | How many clubs have total medals less than 10? |
PRAGMA foreign_keys = ON;
CREATE TABLE "club" (
"Club_ID" int,
"name" text,
"Region" text,
"Start_year" text,
PRIMARY KEY ("Club_ID")
);
CREATE TABLE "club_rank" (
"Rank" real,
"Club_ID" int,
"Gold" real,
"Silver" real,
"Bronze" real,
"Total" real,
PRIMARY KEY ("Rank","Club_ID")
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "player" (
"Player_ID" int,
"name" text,
"Position" text,
"Club_ID" int,
"Apps" real,
"Tries" real,
"Goals" text,
"Points" real,
PRIMARY KEY ("Player_ID"),
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "competition" (
"Competition_ID" int,
"Year" real,
"Competition_type" text,
"Country" text,
PRIMARY KEY ("Competition_ID")
);
CREATE TABLE "competition_result" (
"Competition_ID" int,
"Club_ID_1" int,
"Club_ID_2" int,
"Score" text,
PRIMARY KEY ("Competition_ID","Club_ID_1","Club_ID_2"),
FOREIGN KEY (`Club_ID_1`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Club_ID_2`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Competition_ID`) REFERENCES `competition`(`Competition_ID`)
);
INSERT INTO "club" VALUES (1,"AIB","USA","2009");
INSERT INTO "club_rank" VALUES ("1",2,"11","11","9","31");
INSERT INTO "player" VALUES (1,"Michael Platt","Full Back",1,"20","5","0","20");
INSERT INTO "competition" VALUES (1,"2006","Friendly","Italy");
INSERT INTO "competition_result" VALUES (1,1,2,"11:10");
|
sports_competition | SELECT count(*) FROM club_rank WHERE Total < 10 | What is the total number of clubs that have less than 10 medals in total? |
PRAGMA foreign_keys = ON;
CREATE TABLE "club" (
"Club_ID" int,
"name" text,
"Region" text,
"Start_year" text,
PRIMARY KEY ("Club_ID")
);
CREATE TABLE "club_rank" (
"Rank" real,
"Club_ID" int,
"Gold" real,
"Silver" real,
"Bronze" real,
"Total" real,
PRIMARY KEY ("Rank","Club_ID")
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "player" (
"Player_ID" int,
"name" text,
"Position" text,
"Club_ID" int,
"Apps" real,
"Tries" real,
"Goals" text,
"Points" real,
PRIMARY KEY ("Player_ID"),
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "competition" (
"Competition_ID" int,
"Year" real,
"Competition_type" text,
"Country" text,
PRIMARY KEY ("Competition_ID")
);
CREATE TABLE "competition_result" (
"Competition_ID" int,
"Club_ID_1" int,
"Club_ID_2" int,
"Score" text,
PRIMARY KEY ("Competition_ID","Club_ID_1","Club_ID_2"),
FOREIGN KEY (`Club_ID_1`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Club_ID_2`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Competition_ID`) REFERENCES `competition`(`Competition_ID`)
);
INSERT INTO "club" VALUES (1,"AIB","USA","2009");
INSERT INTO "club_rank" VALUES ("1",2,"11","11","9","31");
INSERT INTO "player" VALUES (1,"Michael Platt","Full Back",1,"20","5","0","20");
INSERT INTO "competition" VALUES (1,"2006","Friendly","Italy");
INSERT INTO "competition_result" VALUES (1,1,2,"11:10");
|
sports_competition | SELECT name FROM club ORDER BY Start_year ASC | List all club names in ascending order of start year. |
PRAGMA foreign_keys = ON;
CREATE TABLE "club" (
"Club_ID" int,
"name" text,
"Region" text,
"Start_year" text,
PRIMARY KEY ("Club_ID")
);
CREATE TABLE "club_rank" (
"Rank" real,
"Club_ID" int,
"Gold" real,
"Silver" real,
"Bronze" real,
"Total" real,
PRIMARY KEY ("Rank","Club_ID")
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "player" (
"Player_ID" int,
"name" text,
"Position" text,
"Club_ID" int,
"Apps" real,
"Tries" real,
"Goals" text,
"Points" real,
PRIMARY KEY ("Player_ID"),
FOREIGN KEY (`Club_ID`) REFERENCES `club`(`Club_ID`)
);
CREATE TABLE "competition" (
"Competition_ID" int,
"Year" real,
"Competition_type" text,
"Country" text,
PRIMARY KEY ("Competition_ID")
);
CREATE TABLE "competition_result" (
"Competition_ID" int,
"Club_ID_1" int,
"Club_ID_2" int,
"Score" text,
PRIMARY KEY ("Competition_ID","Club_ID_1","Club_ID_2"),
FOREIGN KEY (`Club_ID_1`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Club_ID_2`) REFERENCES `club`(`Club_ID`),
FOREIGN KEY (`Competition_ID`) REFERENCES `competition`(`Competition_ID`)
);
INSERT INTO "club" VALUES (1,"AIB","USA","2009");
INSERT INTO "club_rank" VALUES ("1",2,"11","11","9","31");
INSERT INTO "player" VALUES (1,"Michael Platt","Full Back",1,"20","5","0","20");
INSERT INTO "competition" VALUES (1,"2006","Friendly","Italy");
INSERT INTO "competition_result" VALUES (1,1,2,"11:10");
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.