db_id
stringclasses
146 values
question
stringlengths
3
224
sql
stringlengths
18
577
database_schema
stringclasses
146 values
behavior_monitoring
List all information about the assessment notes sorted by date in ascending order.
SELECT * FROM Assessment_Notes ORDER BY date_of_notes ASC
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
List all cities of addresses in alphabetical order.
SELECT city FROM Addresses ORDER BY city
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
Find the first names and last names of teachers in alphabetical order of last name.
SELECT first_name , last_name FROM Teachers ORDER BY last_name
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
Find all information about student addresses, and sort by monthly rental in descending order.
SELECT * FROM Student_Addresses ORDER BY monthly_rental DESC
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
Find the id and first name of the student that has the most number of assessment notes?
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
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
Find the ids and first names of the 3 teachers that have the most number of assessment notes?
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
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
Find the id and last name of the student that has the most behavior incidents?
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
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
Find the id and last name of the teacher that has the most detentions with detention type code "AFTER"?
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
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
What are the id and first name of the student whose addresses have the highest average monthly rental?
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
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
Find the id and city of the student address with the highest average monthly rental.
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
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
What are the code and description of the most frequent behavior incident type?
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
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
What are the code and description of the least frequent detention type ?
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
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
Find the dates of assessment notes for students with first name "Fanny".
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"
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
Find the texts of assessment notes for teachers with last name "Schuster".
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"
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
Find the start and end dates of behavior incidents of students with last name "Fahey".
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"
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
Find the start and end dates of detentions of teachers with last name "Schultz".
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"
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
What are the id and zip code of the address with the highest monthly rental?
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
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
What is the cell phone number of the student whose address has the lowest monthly rental?
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
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
What are the monthly rentals of student addresses in Texas state?
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"
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
What are the first names and last names of students with address in Wisconsin state?
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"
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
What are the line 1 and average monthly rentals of all student addresses?
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
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
What is the zip code of the address where the teacher with first name "Lyla" lives?
SELECT T1.zip_postcode FROM Addresses AS T1 JOIN Teachers AS T2 ON T1.address_id = T2.address_id WHERE T2.first_name = "Lyla"
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
What are the email addresses of teachers whose address has zip code "918"?
SELECT T2.email_address FROM Addresses AS T1 JOIN Teachers AS T2 ON T1.address_id = T2.address_id WHERE T1.zip_postcode = "918"
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
How many students are not involved in any behavior incident?
SELECT count(*) FROM STUDENTS WHERE student_id NOT IN ( SELECT student_id FROM Behavior_Incident )
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
Find the last names of teachers who are not involved in any detention.
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
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
behavior_monitoring
What are the line 1 of addresses shared by some students and some teachers?
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
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ) 3 rows from Ref_Address_Types table: address_type_code address_type_description BILL Billing HOME Home or Residence CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ) 3 rows from Ref_Detention_Type table: detention_type_code detention_type_description BREAK During Break time AFTER After School LUNCH Lunch-time CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ) 3 rows from Ref_Incident_Type table: incident_type_code incident_type_description NOISE Noise VIOLENCE Violence DISTURB Disturbance 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) ) 3 rows from Addresses table: address_id line_1 line_2 line_3 city zip_postcode state_province_county country other_address_details 1 020 Orie Canyon None None North Loyceville 197 Hawaii USA None 2 1333 Boyle Lane None None West Sean 937 Illinois USA None 3 027 Kim Divide Apt. 492 None None Beierview 918 Texas USA None 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` ) ) 3 rows from Students table: student_id address_id first_name middle_name last_name cell_mobile_number email_address date_first_rental date_left_university other_student_details 1 19 Emma Frederic Rohan 235.899.9744 derrick.jenkins@example.com 2017-12-05 15:20:04 2018-03-03 03:33:05 None 2 9 Louvenia Fatima Hansen 1-247-673-8446 rohan.clarabelle@example.org 2017-08-08 22:30:36 2018-02-24 11:12:11 None 3 10 Rhea Gardner Bergnaum 1-751-162-9676x115 kkirlin@example.org 2017-11-15 04:57:28 2018-03-19 12:49:20 None 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` ) ) 3 rows from Teachers table: teacher_id address_id first_name middle_name last_name gender cell_mobile_number email_address other_details 1 15 Lyla Wilson Medhurst 1 792.333.7714 ohammes@example.com None 2 7 Sid Tremayne Brakus 1 202.626.1698x9242 deborah37@example.com None 3 8 Trystan Alexane Schuster 1 583-467-0403x647 hilll.kitty@example.com None 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` ) ) 3 rows from Assessment_Notes table: notes_id student_id teacher_id date_of_notes text_of_notes other_details 1 7 3 1978-04-15 04:49:18 None None 2 11 10 2005-06-30 02:48:35 None None 3 15 3 1988-06-09 00:24:01 None None 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` ) ) 3 rows from Behavior_Incident table: incident_id incident_type_code student_id date_incident_start date_incident_end incident_summary recommendations other_details 1 NOISE 6 2017-07-09 10:04:13 2018-03-08 14:08:54 None None None 2 DISTURB 13 2018-01-31 10:51:13 2018-03-18 18:40:05 None None None 3 VIOLENCE 1 2017-10-10 22:43:54 2018-03-22 02:10:35 None Transfer schools None 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` ) ) 3 rows from Detention table: detention_id detention_type_code teacher_id datetime_detention_start datetime_detention_end detention_summary other_details 1 AFTER 7 2017-09-05 00:38:25 2018-03-08 02:08:32 None None 2 AFTER 14 2018-01-10 08:09:02 2018-03-07 04:24:48 None None 3 BREAK 11 2017-12-14 06:40:29 2018-03-08 09:16:38 None None 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` ) ) 3 rows from Student_Addresses table: student_id address_id date_address_from date_address_to monthly_rental other_details 6 12 2017-10-16 13:56:34 2018-03-15 10:37:19 826.4319 house 3 18 2017-06-19 12:39:39 2018-03-02 00:19:57 1113.0996 house 8 1 2017-10-31 12:40:34 2018-02-25 05:21:34 1297.3186 apartment 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` ) ) 3 rows from Students_in_Detention table: student_id detention_id incident_id 3 15 1 8 13 3 11 6 11
assets_maintenance
Which assets have 2 parts and have less than 2 fault logs? List the asset id and detail.
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
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
How many assets does each maintenance contract contain? List the number and the contract id.
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
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
How many assets does each third party company supply? List the count and the company id.
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
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
Which third party companies have at least 2 maintenance engineers or have at least 2 maintenance contracts? List the company id and name.
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
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
What is the name and id of the staff who recorded the fault log but has not contacted any visiting engineers?
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
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
Which engineer has visited the most times? Show the engineer id, first name and last name.
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
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
Which parts have more than 2 faults? Show the part name and id.
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
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
List all every engineer's first name, last name, details and coresponding skill description.
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
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
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.
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
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
How many assets can each parts be used in? List the part name and the number.
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
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
What are all the fault descriptions and the fault status of all the faults recoreded in the logs?
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
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
How many engineer visits are required at most for a single fault log? List the number and the log entry id.
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
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
What are all the distinct last names of all the engineers?
SELECT DISTINCT last_name FROM Maintenance_Engineers
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
How many fault status codes are recorded in the fault log parts table?
SELECT DISTINCT fault_status FROM Fault_Log_Parts
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
Which engineers have never visited to maintain the assets? List the engineer first name and last name.
SELECT first_name , last_name FROM Maintenance_Engineers WHERE engineer_id NOT IN (SELECT engineer_id FROM Engineer_Visits)
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
List the asset id, details, make and model for every asset.
SELECT asset_id , asset_details , asset_make , asset_model FROM Assets
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
When was the first asset acquired?
SELECT asset_acquired_date FROM Assets ORDER BY asset_acquired_date ASC LIMIT 1
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
Which part fault requires the most number of skills to fix? List part id and name.
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
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
Which kind of part has the least number of faults? List the part name.
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
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
Among those engineers who have visited, which engineer makes the least number of visits? List the engineer id, first name and last name.
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
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
Which staff have contacted which engineers? List the staff name and the engineer first name and last name.
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
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
Which fault log included the most number of faulty parts? List the fault log id, description and record time.
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
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
Which skill is used in fixing the most number of faults? List the skill id and description.
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
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
What are all the distinct asset models?
SELECT DISTINCT asset_model FROM Assets
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
List the all the assets make, model, details by the disposed date ascendingly.
SELECT asset_make , asset_model , asset_details FROM Assets ORDER BY asset_disposed_date ASC
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
Which part has the least chargeable amount? List the part id and amount.
SELECT part_id , chargeable_amount FROM Parts ORDER BY chargeable_amount ASC LIMIT 1
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
Which company started the earliest the maintenance contract? Show the company name.
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
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
What is the description of the type of the company who concluded its contracts most recently?
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
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
Which gender makes up the majority of the staff?
SELECT gender FROM staff GROUP BY gender ORDER BY count(*) DESC LIMIT 1
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
How many engineers did each staff contact? List both the contact staff name and number of engineers contacted.
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
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
assets_maintenance
Which assets did not incur any fault log? List the asset model.
SELECT asset_model FROM Assets WHERE asset_id NOT IN (SELECT asset_id FROM Fault_Log)
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) ) 3 rows from Third_Party_Companies table: company_id company_type company_name company_address other_company_details 1 Maintenance Contractor Langworth-Funk 615 Jacobs Mews Uganda 2 Maintenance Contractor McDermott Group 873 Conrad Creek Apt. 286 China 3 Maintenance Contractor Schuppe-Carroll 066 Bechtelar Ridge United Arab Emirates 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` ) ) 3 rows from Maintenance_Contracts table: maintenance_contract_id maintenance_contract_company_id contract_start_date contract_end_date other_contract_details 1 15 2017-09-13 11:51:29 2018-03-16 21:21:50 None 2 9 2017-12-18 11:43:16 2018-03-22 06:00:37 None 3 11 2017-05-06 02:32:19 2018-03-20 14:02:54 None 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) ) 3 rows from Parts table: part_id part_name chargeable_yn chargeable_amount other_part_details 1 top 0 4 None 2 middle 1 9 None 3 package 1 9 None CREATE TABLE `Skills` ( `skill_id` INTEGER PRIMARY KEY, `skill_code` VARCHAR(20), `skill_description` VARCHAR(255) ) 3 rows from Skills table: skill_id skill_code skill_description 1 ELEC Electrical 2 MECH Mechanical 3 TV TV, Video CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `staff_name` VARCHAR(255), `gender` VARCHAR(1), `other_staff_details` VARCHAR(255) ) 3 rows from Staff table: staff_id staff_name gender other_staff_details 1 Audreanne 1 Manager 2 Berneice 1 Manager 3 Helena 1 None 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` ) ) 3 rows from Assets table: asset_id maintenance_contract_id supplier_company_id asset_details asset_make asset_model asset_acquired_date asset_disposed_date other_asset_details 1 2 2 dell laptop1 PT 58 ub 2017-12-25 00:31:27 2018-03-14 10:50:00 None 2 14 1 dell laptop2 IN 35 xt 2018-01-27 00:59:46 2018-03-20 04:24:09 None 3 7 2 dell laptop3 IT 63 ok 2017-09-07 08:13:15 2018-03-08 20:50:40 Bad condition 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` ) ) 3 rows from Asset_Parts table: asset_id part_id 5 3 3 3 10 1 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` ) ) 3 rows from Maintenance_Engineers table: engineer_id company_id first_name last_name other_details 1 14 Etha Reinger Skilled 2 2 Clemens Orn None 3 6 Samanta Hauck None 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` ) ) 3 rows from Engineer_Skills table: engineer_id skill_id 10 2 10 1 15 1 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` ) ) 3 rows from Fault_Log table: fault_log_entry_id asset_id recorded_by_staff_id fault_log_entry_datetime fault_description other_fault_details 1 3 14 2018-03-21 04:25:00 system error None 2 7 4 2018-03-13 09:43:05 system error None 3 6 9 2018-02-24 09:28:20 system error None 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` ) ) 3 rows from Engineer_Visits table: engineer_visit_id contact_staff_id engineer_id fault_log_entry_id fault_status visit_start_datetime visit_end_datetime other_visit_details 1 8 8 13 Waiting 1978-10-12 23:14:40 1988-01-07 06:41:51 None 2 7 15 13 Return 1980-05-02 23:31:18 1990-08-30 22:44:16 None 3 7 15 4 Waiting 2010-02-23 18:16:23 1982-05-13 02:08:41 None 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` ) ) 3 rows from Part_Faults table: part_fault_id part_id fault_short_name fault_description other_fault_details 1 1 PW Package Wrong None 2 1 PW Package Wrong None 3 3 TW Top Parts Wrong None 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` ) ) 3 rows from Fault_Log_Parts table: fault_log_entry_id part_fault_id fault_status 12 3 Reported 7 4 Reported 1 9 Return 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` ) ) 3 rows from Skills_Required_To_Fix table: part_fault_id skill_id 3 2 12 3 6 1
station_weather
list the local authorities and services provided by all stations.
SELECT local_authority , services FROM station
CREATE TABLE "train" ( "id" int, "train_number" int, "name" text, "origin" text, "destination" text, "time" text, "interval" text, primary key ("id") ) 3 rows from train table: id train_number name origin destination time interval 1 16724 Ananthapuri Express Trivandrum Chennai 17:15 Daily 2 16127 Guruvayur Express Chennai Guruvayur 22:10 Daily 3 16128 Guruvayur Express Guruvayur Chennai 4:49 Daily CREATE TABLE "station" ( "id" int, "network_name" text, "services" text, "local_authority" text, primary key ("id") ) 3 rows from station table: id network_name services local_authority 1 Amersham Metropolitan line and Chiltern Railways Chiltern 2 Bushey London Overground and London Midland Watford 3 Brentwood Greater Anglia Brentwood 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") ) 3 rows from route table: train_id station_id 1 1 1 2 1 3 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") ) 3 rows from weekly_weather table: station_id day_of_week high_temperature low_temperature precipitation wind_speed_mph 1 Monday 59 54 90.0 13 1 Tuesday 66 55 20.0 12 1 Wednesday 60 52 10.0 14
station_weather
show all train numbers and names ordered by their time from early to late.
SELECT train_number , name FROM train ORDER BY TIME
CREATE TABLE "train" ( "id" int, "train_number" int, "name" text, "origin" text, "destination" text, "time" text, "interval" text, primary key ("id") ) 3 rows from train table: id train_number name origin destination time interval 1 16724 Ananthapuri Express Trivandrum Chennai 17:15 Daily 2 16127 Guruvayur Express Chennai Guruvayur 22:10 Daily 3 16128 Guruvayur Express Guruvayur Chennai 4:49 Daily CREATE TABLE "station" ( "id" int, "network_name" text, "services" text, "local_authority" text, primary key ("id") ) 3 rows from station table: id network_name services local_authority 1 Amersham Metropolitan line and Chiltern Railways Chiltern 2 Bushey London Overground and London Midland Watford 3 Brentwood Greater Anglia Brentwood 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") ) 3 rows from route table: train_id station_id 1 1 1 2 1 3 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") ) 3 rows from weekly_weather table: station_id day_of_week high_temperature low_temperature precipitation wind_speed_mph 1 Monday 59 54 90.0 13 1 Tuesday 66 55 20.0 12 1 Wednesday 60 52 10.0 14
station_weather
Give me the times and numbers of all trains that go to Chennai, ordered by time.
SELECT TIME , train_number FROM train WHERE destination = 'Chennai' ORDER BY TIME
CREATE TABLE "train" ( "id" int, "train_number" int, "name" text, "origin" text, "destination" text, "time" text, "interval" text, primary key ("id") ) 3 rows from train table: id train_number name origin destination time interval 1 16724 Ananthapuri Express Trivandrum Chennai 17:15 Daily 2 16127 Guruvayur Express Chennai Guruvayur 22:10 Daily 3 16128 Guruvayur Express Guruvayur Chennai 4:49 Daily CREATE TABLE "station" ( "id" int, "network_name" text, "services" text, "local_authority" text, primary key ("id") ) 3 rows from station table: id network_name services local_authority 1 Amersham Metropolitan line and Chiltern Railways Chiltern 2 Bushey London Overground and London Midland Watford 3 Brentwood Greater Anglia Brentwood 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") ) 3 rows from route table: train_id station_id 1 1 1 2 1 3 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") ) 3 rows from weekly_weather table: station_id day_of_week high_temperature low_temperature precipitation wind_speed_mph 1 Monday 59 54 90.0 13 1 Tuesday 66 55 20.0 12 1 Wednesday 60 52 10.0 14
station_weather
How many trains have 'Express' in their names?
SELECT count(*) FROM train WHERE name LIKE "%Express%"
CREATE TABLE "train" ( "id" int, "train_number" int, "name" text, "origin" text, "destination" text, "time" text, "interval" text, primary key ("id") ) 3 rows from train table: id train_number name origin destination time interval 1 16724 Ananthapuri Express Trivandrum Chennai 17:15 Daily 2 16127 Guruvayur Express Chennai Guruvayur 22:10 Daily 3 16128 Guruvayur Express Guruvayur Chennai 4:49 Daily CREATE TABLE "station" ( "id" int, "network_name" text, "services" text, "local_authority" text, primary key ("id") ) 3 rows from station table: id network_name services local_authority 1 Amersham Metropolitan line and Chiltern Railways Chiltern 2 Bushey London Overground and London Midland Watford 3 Brentwood Greater Anglia Brentwood 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") ) 3 rows from route table: train_id station_id 1 1 1 2 1 3 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") ) 3 rows from weekly_weather table: station_id day_of_week high_temperature low_temperature precipitation wind_speed_mph 1 Monday 59 54 90.0 13 1 Tuesday 66 55 20.0 12 1 Wednesday 60 52 10.0 14
station_weather
Find the number and time of the train that goes from Chennai to Guruvayur.
SELECT train_number , TIME FROM train WHERE origin = 'Chennai' AND destination = 'Guruvayur'
CREATE TABLE "train" ( "id" int, "train_number" int, "name" text, "origin" text, "destination" text, "time" text, "interval" text, primary key ("id") ) 3 rows from train table: id train_number name origin destination time interval 1 16724 Ananthapuri Express Trivandrum Chennai 17:15 Daily 2 16127 Guruvayur Express Chennai Guruvayur 22:10 Daily 3 16128 Guruvayur Express Guruvayur Chennai 4:49 Daily CREATE TABLE "station" ( "id" int, "network_name" text, "services" text, "local_authority" text, primary key ("id") ) 3 rows from station table: id network_name services local_authority 1 Amersham Metropolitan line and Chiltern Railways Chiltern 2 Bushey London Overground and London Midland Watford 3 Brentwood Greater Anglia Brentwood 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") ) 3 rows from route table: train_id station_id 1 1 1 2 1 3 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") ) 3 rows from weekly_weather table: station_id day_of_week high_temperature low_temperature precipitation wind_speed_mph 1 Monday 59 54 90.0 13 1 Tuesday 66 55 20.0 12 1 Wednesday 60 52 10.0 14
station_weather
Find the number of trains starting from each origin.
SELECT origin , count(*) FROM train GROUP BY origin
CREATE TABLE "train" ( "id" int, "train_number" int, "name" text, "origin" text, "destination" text, "time" text, "interval" text, primary key ("id") ) 3 rows from train table: id train_number name origin destination time interval 1 16724 Ananthapuri Express Trivandrum Chennai 17:15 Daily 2 16127 Guruvayur Express Chennai Guruvayur 22:10 Daily 3 16128 Guruvayur Express Guruvayur Chennai 4:49 Daily CREATE TABLE "station" ( "id" int, "network_name" text, "services" text, "local_authority" text, primary key ("id") ) 3 rows from station table: id network_name services local_authority 1 Amersham Metropolitan line and Chiltern Railways Chiltern 2 Bushey London Overground and London Midland Watford 3 Brentwood Greater Anglia Brentwood 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") ) 3 rows from route table: train_id station_id 1 1 1 2 1 3 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") ) 3 rows from weekly_weather table: station_id day_of_week high_temperature low_temperature precipitation wind_speed_mph 1 Monday 59 54 90.0 13 1 Tuesday 66 55 20.0 12 1 Wednesday 60 52 10.0 14
station_weather
Find the name of the train whose route runs through greatest number of stations.
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
CREATE TABLE "train" ( "id" int, "train_number" int, "name" text, "origin" text, "destination" text, "time" text, "interval" text, primary key ("id") ) 3 rows from train table: id train_number name origin destination time interval 1 16724 Ananthapuri Express Trivandrum Chennai 17:15 Daily 2 16127 Guruvayur Express Chennai Guruvayur 22:10 Daily 3 16128 Guruvayur Express Guruvayur Chennai 4:49 Daily CREATE TABLE "station" ( "id" int, "network_name" text, "services" text, "local_authority" text, primary key ("id") ) 3 rows from station table: id network_name services local_authority 1 Amersham Metropolitan line and Chiltern Railways Chiltern 2 Bushey London Overground and London Midland Watford 3 Brentwood Greater Anglia Brentwood 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") ) 3 rows from route table: train_id station_id 1 1 1 2 1 3 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") ) 3 rows from weekly_weather table: station_id day_of_week high_temperature low_temperature precipitation wind_speed_mph 1 Monday 59 54 90.0 13 1 Tuesday 66 55 20.0 12 1 Wednesday 60 52 10.0 14
station_weather
Find the number of trains for each station, as well as the station network name and services.
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
CREATE TABLE "train" ( "id" int, "train_number" int, "name" text, "origin" text, "destination" text, "time" text, "interval" text, primary key ("id") ) 3 rows from train table: id train_number name origin destination time interval 1 16724 Ananthapuri Express Trivandrum Chennai 17:15 Daily 2 16127 Guruvayur Express Chennai Guruvayur 22:10 Daily 3 16128 Guruvayur Express Guruvayur Chennai 4:49 Daily CREATE TABLE "station" ( "id" int, "network_name" text, "services" text, "local_authority" text, primary key ("id") ) 3 rows from station table: id network_name services local_authority 1 Amersham Metropolitan line and Chiltern Railways Chiltern 2 Bushey London Overground and London Midland Watford 3 Brentwood Greater Anglia Brentwood 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") ) 3 rows from route table: train_id station_id 1 1 1 2 1 3 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") ) 3 rows from weekly_weather table: station_id day_of_week high_temperature low_temperature precipitation wind_speed_mph 1 Monday 59 54 90.0 13 1 Tuesday 66 55 20.0 12 1 Wednesday 60 52 10.0 14
station_weather
What is the average high temperature for each day of week?
SELECT avg(high_temperature) , day_of_week FROM weekly_weather GROUP BY day_of_week
CREATE TABLE "train" ( "id" int, "train_number" int, "name" text, "origin" text, "destination" text, "time" text, "interval" text, primary key ("id") ) 3 rows from train table: id train_number name origin destination time interval 1 16724 Ananthapuri Express Trivandrum Chennai 17:15 Daily 2 16127 Guruvayur Express Chennai Guruvayur 22:10 Daily 3 16128 Guruvayur Express Guruvayur Chennai 4:49 Daily CREATE TABLE "station" ( "id" int, "network_name" text, "services" text, "local_authority" text, primary key ("id") ) 3 rows from station table: id network_name services local_authority 1 Amersham Metropolitan line and Chiltern Railways Chiltern 2 Bushey London Overground and London Midland Watford 3 Brentwood Greater Anglia Brentwood 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") ) 3 rows from route table: train_id station_id 1 1 1 2 1 3 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") ) 3 rows from weekly_weather table: station_id day_of_week high_temperature low_temperature precipitation wind_speed_mph 1 Monday 59 54 90.0 13 1 Tuesday 66 55 20.0 12 1 Wednesday 60 52 10.0 14
station_weather
Give me the maximum low temperature and average precipitation at the Amersham station.
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"
CREATE TABLE "train" ( "id" int, "train_number" int, "name" text, "origin" text, "destination" text, "time" text, "interval" text, primary key ("id") ) 3 rows from train table: id train_number name origin destination time interval 1 16724 Ananthapuri Express Trivandrum Chennai 17:15 Daily 2 16127 Guruvayur Express Chennai Guruvayur 22:10 Daily 3 16128 Guruvayur Express Guruvayur Chennai 4:49 Daily CREATE TABLE "station" ( "id" int, "network_name" text, "services" text, "local_authority" text, primary key ("id") ) 3 rows from station table: id network_name services local_authority 1 Amersham Metropolitan line and Chiltern Railways Chiltern 2 Bushey London Overground and London Midland Watford 3 Brentwood Greater Anglia Brentwood 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") ) 3 rows from route table: train_id station_id 1 1 1 2 1 3 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") ) 3 rows from weekly_weather table: station_id day_of_week high_temperature low_temperature precipitation wind_speed_mph 1 Monday 59 54 90.0 13 1 Tuesday 66 55 20.0 12 1 Wednesday 60 52 10.0 14
station_weather
Find names and times of trains that run through stations for the local authority Chiltern.
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"
CREATE TABLE "train" ( "id" int, "train_number" int, "name" text, "origin" text, "destination" text, "time" text, "interval" text, primary key ("id") ) 3 rows from train table: id train_number name origin destination time interval 1 16724 Ananthapuri Express Trivandrum Chennai 17:15 Daily 2 16127 Guruvayur Express Chennai Guruvayur 22:10 Daily 3 16128 Guruvayur Express Guruvayur Chennai 4:49 Daily CREATE TABLE "station" ( "id" int, "network_name" text, "services" text, "local_authority" text, primary key ("id") ) 3 rows from station table: id network_name services local_authority 1 Amersham Metropolitan line and Chiltern Railways Chiltern 2 Bushey London Overground and London Midland Watford 3 Brentwood Greater Anglia Brentwood 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") ) 3 rows from route table: train_id station_id 1 1 1 2 1 3 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") ) 3 rows from weekly_weather table: station_id day_of_week high_temperature low_temperature precipitation wind_speed_mph 1 Monday 59 54 90.0 13 1 Tuesday 66 55 20.0 12 1 Wednesday 60 52 10.0 14
station_weather
How many different services are provided by all stations?
SELECT count(DISTINCT services) FROM station
CREATE TABLE "train" ( "id" int, "train_number" int, "name" text, "origin" text, "destination" text, "time" text, "interval" text, primary key ("id") ) 3 rows from train table: id train_number name origin destination time interval 1 16724 Ananthapuri Express Trivandrum Chennai 17:15 Daily 2 16127 Guruvayur Express Chennai Guruvayur 22:10 Daily 3 16128 Guruvayur Express Guruvayur Chennai 4:49 Daily CREATE TABLE "station" ( "id" int, "network_name" text, "services" text, "local_authority" text, primary key ("id") ) 3 rows from station table: id network_name services local_authority 1 Amersham Metropolitan line and Chiltern Railways Chiltern 2 Bushey London Overground and London Midland Watford 3 Brentwood Greater Anglia Brentwood 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") ) 3 rows from route table: train_id station_id 1 1 1 2 1 3 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") ) 3 rows from weekly_weather table: station_id day_of_week high_temperature low_temperature precipitation wind_speed_mph 1 Monday 59 54 90.0 13 1 Tuesday 66 55 20.0 12 1 Wednesday 60 52 10.0 14
station_weather
Find the id and local authority of the station with has the highest average high temperature.
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
CREATE TABLE "train" ( "id" int, "train_number" int, "name" text, "origin" text, "destination" text, "time" text, "interval" text, primary key ("id") ) 3 rows from train table: id train_number name origin destination time interval 1 16724 Ananthapuri Express Trivandrum Chennai 17:15 Daily 2 16127 Guruvayur Express Chennai Guruvayur 22:10 Daily 3 16128 Guruvayur Express Guruvayur Chennai 4:49 Daily CREATE TABLE "station" ( "id" int, "network_name" text, "services" text, "local_authority" text, primary key ("id") ) 3 rows from station table: id network_name services local_authority 1 Amersham Metropolitan line and Chiltern Railways Chiltern 2 Bushey London Overground and London Midland Watford 3 Brentwood Greater Anglia Brentwood 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") ) 3 rows from route table: train_id station_id 1 1 1 2 1 3 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") ) 3 rows from weekly_weather table: station_id day_of_week high_temperature low_temperature precipitation wind_speed_mph 1 Monday 59 54 90.0 13 1 Tuesday 66 55 20.0 12 1 Wednesday 60 52 10.0 14
station_weather
Find the id and local authority of the station whose maximum precipitation is higher than 50.
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
CREATE TABLE "train" ( "id" int, "train_number" int, "name" text, "origin" text, "destination" text, "time" text, "interval" text, primary key ("id") ) 3 rows from train table: id train_number name origin destination time interval 1 16724 Ananthapuri Express Trivandrum Chennai 17:15 Daily 2 16127 Guruvayur Express Chennai Guruvayur 22:10 Daily 3 16128 Guruvayur Express Guruvayur Chennai 4:49 Daily CREATE TABLE "station" ( "id" int, "network_name" text, "services" text, "local_authority" text, primary key ("id") ) 3 rows from station table: id network_name services local_authority 1 Amersham Metropolitan line and Chiltern Railways Chiltern 2 Bushey London Overground and London Midland Watford 3 Brentwood Greater Anglia Brentwood 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") ) 3 rows from route table: train_id station_id 1 1 1 2 1 3 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") ) 3 rows from weekly_weather table: station_id day_of_week high_temperature low_temperature precipitation wind_speed_mph 1 Monday 59 54 90.0 13 1 Tuesday 66 55 20.0 12 1 Wednesday 60 52 10.0 14
station_weather
show the lowest low temperature and highest wind speed in miles per hour.
SELECT min(low_temperature) , max(wind_speed_mph) FROM weekly_weather
CREATE TABLE "train" ( "id" int, "train_number" int, "name" text, "origin" text, "destination" text, "time" text, "interval" text, primary key ("id") ) 3 rows from train table: id train_number name origin destination time interval 1 16724 Ananthapuri Express Trivandrum Chennai 17:15 Daily 2 16127 Guruvayur Express Chennai Guruvayur 22:10 Daily 3 16128 Guruvayur Express Guruvayur Chennai 4:49 Daily CREATE TABLE "station" ( "id" int, "network_name" text, "services" text, "local_authority" text, primary key ("id") ) 3 rows from station table: id network_name services local_authority 1 Amersham Metropolitan line and Chiltern Railways Chiltern 2 Bushey London Overground and London Midland Watford 3 Brentwood Greater Anglia Brentwood 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") ) 3 rows from route table: train_id station_id 1 1 1 2 1 3 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") ) 3 rows from weekly_weather table: station_id day_of_week high_temperature low_temperature precipitation wind_speed_mph 1 Monday 59 54 90.0 13 1 Tuesday 66 55 20.0 12 1 Wednesday 60 52 10.0 14
station_weather
Find the origins from which more than 1 train starts.
SELECT origin FROM train GROUP BY origin HAVING count(*) > 1
CREATE TABLE "train" ( "id" int, "train_number" int, "name" text, "origin" text, "destination" text, "time" text, "interval" text, primary key ("id") ) 3 rows from train table: id train_number name origin destination time interval 1 16724 Ananthapuri Express Trivandrum Chennai 17:15 Daily 2 16127 Guruvayur Express Chennai Guruvayur 22:10 Daily 3 16128 Guruvayur Express Guruvayur Chennai 4:49 Daily CREATE TABLE "station" ( "id" int, "network_name" text, "services" text, "local_authority" text, primary key ("id") ) 3 rows from station table: id network_name services local_authority 1 Amersham Metropolitan line and Chiltern Railways Chiltern 2 Bushey London Overground and London Midland Watford 3 Brentwood Greater Anglia Brentwood 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") ) 3 rows from route table: train_id station_id 1 1 1 2 1 3 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") ) 3 rows from weekly_weather table: station_id day_of_week high_temperature low_temperature precipitation wind_speed_mph 1 Monday 59 54 90.0 13 1 Tuesday 66 55 20.0 12 1 Wednesday 60 52 10.0 14
college_1
Find the number of professors in accounting department.
SELECT count(*) FROM professor AS T1 JOIN department AS T2 ON T1.dept_code = T2.dept_code WHERE DEPT_NAME = "Accounting"
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
How many professors are in the accounting dept?
SELECT count(*) FROM professor AS T1 JOIN department AS T2 ON T1.dept_code = T2.dept_code WHERE DEPT_NAME = "Accounting"
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
How many professors are teaching class with code ACCT-211?
SELECT count(DISTINCT PROF_NUM) FROM CLASS WHERE CRS_CODE = "ACCT-211"
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
How many professors teach a class with the code ACCT-211?
SELECT count(DISTINCT PROF_NUM) FROM CLASS WHERE CRS_CODE = "ACCT-211"
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
What is the first and last name of the professor in biology department?
SELECT T3.EMP_FNAME , T3.EMP_LNAME FROM professor AS T1 JOIN department AS T2 ON T1.dept_code = T2.dept_code JOIN employee AS T3 ON T1.EMP_NUM = T3.EMP_NUM WHERE DEPT_NAME = "Biology"
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
What are the first and last name of all biology professors?
SELECT T3.EMP_FNAME , T3.EMP_LNAME FROM professor AS T1 JOIN department AS T2 ON T1.dept_code = T2.dept_code JOIN employee AS T3 ON T1.EMP_NUM = T3.EMP_NUM WHERE DEPT_NAME = "Biology"
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
What are the first names and date of birth of professors teaching course ACCT-211?
SELECT DISTINCT T1.EMP_FNAME , T1.EMP_DOB FROM employee AS T1 JOIN CLASS AS T2 ON T1.EMP_NUM = T2.PROF_NUM WHERE CRS_CODE = "ACCT-211"
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
What are the first names and birthdates of the professors in charge of ACCT-211?
SELECT DISTINCT T1.EMP_FNAME , T1.EMP_DOB FROM employee AS T1 JOIN CLASS AS T2 ON T1.EMP_NUM = T2.PROF_NUM WHERE CRS_CODE = "ACCT-211"
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
How many classes are professor whose last name is Graztevski has?
SELECT count(*) FROM employee AS T1 JOIN CLASS AS T2 ON T1.EMP_NUM = T2.PROF_NUM WHERE T1.EMP_LNAME = 'Graztevski'
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
How many classes does the professor whose last name is Graztevski teach?
SELECT count(*) FROM employee AS T1 JOIN CLASS AS T2 ON T1.EMP_NUM = T2.PROF_NUM WHERE T1.EMP_LNAME = 'Graztevski'
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
What is the code of the school where the accounting department belongs to?
SELECT school_code FROM department WHERE dept_name = "Accounting"
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
What is the school code of the accounting department?
SELECT school_code FROM department WHERE dept_name = "Accounting"
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
How many credits does course CIS-220 have, and what its description?
SELECT crs_credit , crs_description FROM course WHERE crs_code = 'CIS-220'
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
What is the description for the CIS-220 and how many credits does it have?
SELECT crs_credit , crs_description FROM course WHERE crs_code = 'CIS-220'
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
what is the address of history department?
SELECT dept_address FROM department WHERE dept_name = 'History'
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
Where is the history department?
SELECT dept_address FROM department WHERE dept_name = 'History'
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
How many different locations does the school with code BUS has?
SELECT count(DISTINCT dept_address) FROM department WHERE school_code = 'BUS'
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
What are the different locations of the school with the code BUS?
SELECT count(DISTINCT dept_address) FROM department WHERE school_code = 'BUS'
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
How many different locations does each school have?
SELECT count(DISTINCT dept_address) , school_code FROM department GROUP BY school_code
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
Count different addresses of each school.
SELECT count(DISTINCT dept_address) , school_code FROM department GROUP BY school_code
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
Find the description and credit for the course QM-261?
SELECT crs_credit , crs_description FROM course WHERE crs_code = 'QM-261'
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
What is the course description and number of credits for QM-261?
SELECT crs_credit , crs_description FROM course WHERE crs_code = 'QM-261'
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
Find the number of departments in each school.
SELECT count(DISTINCT dept_name) , school_code FROM department GROUP BY school_code
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
How many departments are in each school?
SELECT count(DISTINCT dept_name) , school_code FROM department GROUP BY school_code
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
Find the number of different departments in each school whose number of different departments is less than 5.
SELECT count(DISTINCT dept_name) , school_code FROM department GROUP BY school_code HAVING count(DISTINCT dept_name) < 5
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
How many different departments are there in each school that has less than 5 apartments?
SELECT count(DISTINCT dept_name) , school_code FROM department GROUP BY school_code HAVING count(DISTINCT dept_name) < 5
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228
college_1
How many sections does each course has?
SELECT count(*) , crs_code FROM CLASS GROUP BY crs_code
CREATE TABLE CLASS ( CLASS_CODE varchar(5) PRIMARY KEY, CRS_CODE varchar(10), CLASS_SECTION varchar(2), CLASS_TIME varchar(20), CLASS_ROOM varchar(8), PROF_NUM int, FOREIGN KEY (CRS_CODE) REFERENCES COURSE(CRS_CODE) FOREIGN KEY (PROF_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from CLASS table: CLASS_CODE CRS_CODE CLASS_SECTION CLASS_TIME CLASS_ROOM PROF_NUM 10012 ACCT-211 1 MWF 8:00-8:50 a.m. BUS311 105 10013 ACCT-211 2 MWF 9:00-9:50 a.m. BUS200 105 10014 ACCT-211 3 TTh 2:30-3:45 p.m. BUS252 342 CREATE TABLE COURSE ( CRS_CODE varchar(10) PRIMARY KEY, DEPT_CODE varchar(10), CRS_DESCRIPTION varchar(35), CRS_CREDIT float(8), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from COURSE table: CRS_CODE DEPT_CODE CRS_DESCRIPTION CRS_CREDIT ACCT-211 ACCT Accounting I 3.0 ACCT-212 ACCT Accounting II 3.0 CIS-220 CIS Intro. to Microcomputing 3.0 CREATE TABLE DEPARTMENT ( DEPT_CODE varchar(10) PRIMARY KEY, DEPT_NAME varchar(30), SCHOOL_CODE varchar(8), EMP_NUM int, DEPT_ADDRESS varchar(20), DEPT_EXTENSION varchar(4), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM) ) 3 rows from DEPARTMENT table: DEPT_CODE DEPT_NAME SCHOOL_CODE EMP_NUM DEPT_ADDRESS DEPT_EXTENSION ACCT Accounting BUS 114 KLR 211, Box 52 3119 ART Fine Arts A&SCI 435 BBG 185, Box 128 2278 BIOL Biology A&SCI 387 AAK 230, Box 415 4117 CREATE TABLE EMPLOYEE ( EMP_NUM int PRIMARY KEY, EMP_LNAME varchar(15), EMP_FNAME varchar(12), EMP_INITIAL varchar(1), EMP_JOBCODE varchar(5), EMP_HIREDATE datetime, EMP_DOB datetime ) 3 rows from EMPLOYEE table: EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_JOBCODE EMP_HIREDATE EMP_DOB 100 Worley James F CUST 1978-2-23 1950-6-12 101 Ramso Henry B CUST 1994-11-15 1961-11-2 102 Edwards Rosemary D TECH 1990-7-23 1953-7-3 CREATE TABLE ENROLL ( CLASS_CODE varchar(5), STU_NUM int, ENROLL_GRADE varchar(50), FOREIGN KEY (CLASS_CODE) REFERENCES CLASS(CLASS_CODE) FOREIGN KEY (STU_NUM) REFERENCES STUDENT(STU_NUM) ) 3 rows from ENROLL table: CLASS_CODE STU_NUM ENROLL_GRADE 10014 321452 C 10014 324257 B 10018 321452 A CREATE TABLE PROFESSOR ( EMP_NUM int, DEPT_CODE varchar(10), PROF_OFFICE varchar(50), PROF_EXTENSION varchar(4), PROF_HIGH_DEGREE varchar(5), FOREIGN KEY (EMP_NUM) REFERENCES EMPLOYEE(EMP_NUM), FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from PROFESSOR table: EMP_NUM DEPT_CODE PROF_OFFICE PROF_EXTENSION PROF_HIGH_DEGREE 103 HIST DRE 156 6783 Ph.D. 104 ENG DRE 102 5561 MA 105 ACCT KLR 229D 8665 Ph.D. CREATE TABLE STUDENT ( STU_NUM int PRIMARY KEY, STU_LNAME varchar(15), STU_FNAME varchar(15), STU_INIT varchar(1), STU_DOB datetime, STU_HRS int, STU_CLASS varchar(2), STU_GPA float(8), STU_TRANSFER numeric, DEPT_CODE varchar(18), STU_PHONE varchar(4), PROF_NUM int, FOREIGN KEY (DEPT_CODE) REFERENCES DEPARTMENT(DEPT_CODE) ) 3 rows from STUDENT table: STU_NUM STU_LNAME STU_FNAME STU_INIT STU_DOB STU_HRS STU_CLASS STU_GPA STU_TRANSFER DEPT_CODE STU_PHONE PROF_NUM 321452 Bowser William C 1975-2-12 42 So 2.84 0 BIOL 2134 205 324257 Smithson Anne K 1981-11-15 81 Jr 3.27 1 CIS 2256 222 324258 Brewer Juliette 1969-8-23 36 So 2.26 1 ACCT 2256 228