db_id
stringclasses
146 values
question
stringlengths
3
224
sql
stringlengths
18
577
database_schema
stringclasses
146 values
e_learning
List each test result and its count in descending order of count.
SELECT test_result , COUNT(*) FROM Student_Tests_Taken GROUP BY test_result ORDER BY COUNT(*) DESC
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
For each distinct test result, find the number of students who got the result.
SELECT test_result , COUNT(*) FROM Student_Tests_Taken GROUP BY test_result ORDER BY COUNT(*) DESC
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Find the login name of the course author that teaches the course with name "advanced database".
SELECT T1.login_name FROM Course_Authors_and_Tutors AS T1 JOIN Courses AS T2 ON T1.author_id = T2.author_id WHERE T2.course_name = "advanced database"
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Which course author teaches the "advanced database" course? Give me his or her login name.
SELECT T1.login_name FROM Course_Authors_and_Tutors AS T1 JOIN Courses AS T2 ON T1.author_id = T2.author_id WHERE T2.course_name = "advanced database"
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Find the addresses of the course authors who teach the course with name "operating system" or "data structure".
SELECT T1.address_line_1 FROM Course_Authors_and_Tutors AS T1 JOIN Courses AS T2 ON T1.author_id = T2.author_id WHERE T2.course_name = "operating system" OR T2.course_name = "data structure"
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
What are the addresses of the course authors who teach either "operating system" or "data structure" course.
SELECT T1.address_line_1 FROM Course_Authors_and_Tutors AS T1 JOIN Courses AS T2 ON T1.author_id = T2.author_id WHERE T2.course_name = "operating system" OR T2.course_name = "data structure"
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Find the personal name, family name, and author ID of the course author that teaches the most courses.
SELECT T1.personal_name , T1.family_name , T2.author_id FROM Course_Authors_and_Tutors AS T1 JOIN Courses AS T2 ON T1.author_id = T2.author_id GROUP BY T2.author_id ORDER BY COUNT(*) DESC LIMIT 1
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
What are the personal name, family name, and author ID of the course author who teaches the most courses?
SELECT T1.personal_name , T1.family_name , T2.author_id FROM Course_Authors_and_Tutors AS T1 JOIN Courses AS T2 ON T1.author_id = T2.author_id GROUP BY T2.author_id ORDER BY COUNT(*) DESC LIMIT 1
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Find the addresses and author IDs of the course authors that teach at least two courses.
SELECT T1.address_line_1 , T2.author_id FROM Course_Authors_and_Tutors AS T1 JOIN Courses AS T2 ON T1.author_id = T2.author_id GROUP BY T2.author_id HAVING Count(*) >= 2
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Which course authors teach two or more courses? Give me their addresses and author IDs.
SELECT T1.address_line_1 , T2.author_id FROM Course_Authors_and_Tutors AS T1 JOIN Courses AS T2 ON T1.author_id = T2.author_id GROUP BY T2.author_id HAVING Count(*) >= 2
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Find the names of courses taught by the tutor who has personal name "Julio".
SELECT T2.course_name FROM Course_Authors_and_Tutors AS T1 JOIN Courses AS T2 ON T1.author_id = T2.author_id WHERE T1.personal_name = "Julio"
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
What are the names of the courses taught by the tutor whose personal name is "Julio"?
SELECT T2.course_name FROM Course_Authors_and_Tutors AS T1 JOIN Courses AS T2 ON T1.author_id = T2.author_id WHERE T1.personal_name = "Julio"
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Find the names and descriptions of courses that belong to the subject named "Computer Science".
SELECT T1.course_name , T1.course_description FROM Courses AS T1 JOIN Subjects AS T2 ON T1.subject_id = T2.subject_id WHERE T2.subject_name = "Computer Science"
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
What are the names and descriptions of the all courses under the "Computer Science" subject?
SELECT T1.course_name , T1.course_description FROM Courses AS T1 JOIN Subjects AS T2 ON T1.subject_id = T2.subject_id WHERE T2.subject_name = "Computer Science"
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Find the subject ID, subject name, and the corresponding number of available courses for each subject.
SELECT T1.subject_id , T2.subject_name , COUNT(*) FROM Courses AS T1 JOIN Subjects AS T2 ON T1.subject_id = T2.subject_id GROUP BY T1.subject_id
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
What are the subject ID, subject name, and the number of available courses for each subject?
SELECT T1.subject_id , T2.subject_name , COUNT(*) FROM Courses AS T1 JOIN Subjects AS T2 ON T1.subject_id = T2.subject_id GROUP BY T1.subject_id
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Find the subject ID, name of subject and the corresponding number of courses for each subject, and sort by the course count in ascending order.
SELECT T1.subject_id , T2.subject_name , COUNT(*) FROM Courses AS T1 JOIN Subjects AS T2 ON T1.subject_id = T2.subject_id GROUP BY T1.subject_id ORDER BY COUNT(*) ASC
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
List the subject ID, name of subject and the number of courses available for each subject in ascending order of the course counts.
SELECT T1.subject_id , T2.subject_name , COUNT(*) FROM Courses AS T1 JOIN Subjects AS T2 ON T1.subject_id = T2.subject_id GROUP BY T1.subject_id ORDER BY COUNT(*) ASC
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
What is the date of enrollment of the course named "Spanish"?
SELECT T2.date_of_enrolment FROM Courses AS T1 JOIN Student_Course_Enrolment AS T2 ON T1.course_id = T2.course_id WHERE T1.course_name = "Spanish"
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Find the the date of enrollment of the "Spanish" course.
SELECT T2.date_of_enrolment FROM Courses AS T1 JOIN Student_Course_Enrolment AS T2 ON T1.course_id = T2.course_id WHERE T1.course_name = "Spanish"
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
What is the name of the course that has the most student enrollment?
SELECT T1.course_name FROM Courses AS T1 JOIN Student_Course_Enrolment AS T2 ON T1.course_id = T2.course_id GROUP BY T1.course_name ORDER BY COUNT(*) DESC LIMIT 1
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Which course is enrolled in by the most students? Give me the course name.
SELECT T1.course_name FROM Courses AS T1 JOIN Student_Course_Enrolment AS T2 ON T1.course_id = T2.course_id GROUP BY T1.course_name ORDER BY COUNT(*) DESC LIMIT 1
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
What are the names of the courses that have exactly 1 student enrollment?
SELECT T1.course_name FROM Courses AS T1 JOIN Student_Course_Enrolment AS T2 ON T1.course_id = T2.course_id GROUP BY T1.course_name HAVING COUNT(*) = 1
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Find the names of the courses that have just one student enrollment.
SELECT T1.course_name FROM Courses AS T1 JOIN Student_Course_Enrolment AS T2 ON T1.course_id = T2.course_id GROUP BY T1.course_name HAVING COUNT(*) = 1
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
What are the descriptions and names of the courses that have student enrollment bigger than 2?
SELECT T1.course_description , T1.course_name FROM Courses AS T1 JOIN Student_Course_Enrolment AS T2 ON T1.course_id = T2.course_id GROUP BY T1.course_name HAVING COUNT(*) > 2
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Return the descriptions and names of the courses that have more than two students enrolled in.
SELECT T1.course_description , T1.course_name FROM Courses AS T1 JOIN Student_Course_Enrolment AS T2 ON T1.course_id = T2.course_id GROUP BY T1.course_name HAVING COUNT(*) > 2
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
What is the name of each course and the corresponding number of student enrollment?
SELECT T1.course_name , COUNT(*) FROM Courses AS T1 JOIN Student_Course_Enrolment AS T2 ON T1.course_id = T2.course_id GROUP BY T1.course_name
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
List the name and the number of enrolled student for each course.
SELECT T1.course_name , COUNT(*) FROM Courses AS T1 JOIN Student_Course_Enrolment AS T2 ON T1.course_id = T2.course_id GROUP BY T1.course_name
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
What are the enrollment dates of all the tests that have result "Pass"?
SELECT T1.date_of_enrolment FROM Student_Course_Enrolment AS T1 JOIN Student_Tests_Taken AS T2 ON T1.registration_id = T2.registration_id WHERE T2.test_result = "Pass"
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Find the enrollment date for all the tests that have "Pass" result.
SELECT T1.date_of_enrolment FROM Student_Course_Enrolment AS T1 JOIN Student_Tests_Taken AS T2 ON T1.registration_id = T2.registration_id WHERE T2.test_result = "Pass"
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
What are the completion dates of all the tests that have result "Fail"?
SELECT T1.date_of_completion FROM Student_Course_Enrolment AS T1 JOIN Student_Tests_Taken AS T2 ON T1.registration_id = T2.registration_id WHERE T2.test_result = "Fail"
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Return the completion date for all the tests that have "Fail" result.
SELECT T1.date_of_completion FROM Student_Course_Enrolment AS T1 JOIN Student_Tests_Taken AS T2 ON T1.registration_id = T2.registration_id WHERE T2.test_result = "Fail"
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
List the dates of enrollment and completion of the student with personal name "Karson".
SELECT T1.date_of_enrolment , T1.date_of_completion FROM Student_Course_Enrolment AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id WHERE T2.personal_name = "Karson"
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
On what dates did the student whose personal name is "Karson" enroll in and complete the courses?
SELECT T1.date_of_enrolment , T1.date_of_completion FROM Student_Course_Enrolment AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id WHERE T2.personal_name = "Karson"
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
List the dates of enrollment and completion of the student with family name "Zieme" and personal name "Bernie".
SELECT T1.date_of_enrolment , T1.date_of_completion FROM Student_Course_Enrolment AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id WHERE T2.family_name = "Zieme" AND T2.personal_name = "Bernie"
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
On what dates did the student with family name "Zieme" and personal name "Bernie" enroll in and complete the courses?
SELECT T1.date_of_enrolment , T1.date_of_completion FROM Student_Course_Enrolment AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id WHERE T2.family_name = "Zieme" AND T2.personal_name = "Bernie"
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Find the student ID and login name of the student with the most course enrollments
SELECT T1.student_id , T2.login_name FROM Student_Course_Enrolment 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 `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
What are the student ID and login name of the student who are enrolled in the most courses?
SELECT T1.student_id , T2.login_name FROM Student_Course_Enrolment 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 `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Find the student ID and personal name of the student with at least two enrollments.
SELECT T1.student_id , T2.personal_name FROM Student_Course_Enrolment AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id GROUP BY T1.student_id HAVING COUNT(*) >= 2
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Which student are enrolled in at least two courses? Give me the student ID and personal name.
SELECT T1.student_id , T2.personal_name FROM Student_Course_Enrolment AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id GROUP BY T1.student_id HAVING COUNT(*) >= 2
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Find the student ID and middle name for all the students with at most two enrollments.
SELECT T1.student_id , T2.middle_name FROM Student_Course_Enrolment AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id GROUP BY T1.student_id HAVING COUNT(*) <= 2
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
What are the student IDs and middle names of the students enrolled in at most two courses?
SELECT T1.student_id , T2.middle_name FROM Student_Course_Enrolment AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id GROUP BY T1.student_id HAVING COUNT(*) <= 2
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Find the personal names of students not enrolled in any course.
SELECT personal_name FROM Students EXCEPT SELECT T1.personal_name FROM Students AS T1 JOIN Student_Course_Enrolment AS T2 ON T1.student_id = T2.student_id
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Which students not enrolled in any course? Find their personal names.
SELECT personal_name FROM Students EXCEPT SELECT T1.personal_name FROM Students AS T1 JOIN Student_Course_Enrolment AS T2 ON T1.student_id = T2.student_id
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
How many students did not have any course enrollment?
SELECT count(*) FROM Students WHERE student_id NOT IN (SELECT student_id FROM Student_Course_Enrolment)
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Count the number of students who did not enroll in any course.
SELECT count(*) FROM Students WHERE student_id NOT IN (SELECT student_id FROM Student_Course_Enrolment)
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Find the common login name of course authors and students.
SELECT login_name FROM Course_Authors_and_Tutors INTERSECT SELECT login_name FROM Students
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
What are the login names used both by some course authors and some students?
SELECT login_name FROM Course_Authors_and_Tutors INTERSECT SELECT login_name FROM Students
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
Find the common personal name of course authors and students.
SELECT personal_name FROM Course_Authors_and_Tutors INTERSECT SELECT personal_name FROM Students
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
e_learning
What are the personal names used both by some course authors and some students?
SELECT personal_name FROM Course_Authors_and_Tutors INTERSECT SELECT personal_name FROM Students
CREATE TABLE `Course_Authors_and_Tutors` ( `author_id` INTEGER PRIMARY KEY, `author_tutor_ATB` VARCHAR(3), `login_name` VARCHAR(40), `password` VARCHAR(40), `personal_name` VARCHAR(80), `middle_name` VARCHAR(80), `family_name` VARCHAR(80), `gender_mf` VARCHAR(1), `address_line_1` VARCHAR(80) ) 3 rows from Course_Authors_and_Tutors table: author_id author_tutor_ATB login_name password personal_name middle_name family_name gender_mf address_line_1 1 331 jmckenzie c40fa148bdd0d2d45cd6e9ec1e685750fe07f81b Cathrine Ruthie Grant 0 756 Monahan Mews\nSpinkashire, NJ 64230-5098 2 975 heidenreich.ara 24b0ee84063c3b017ab1839e01b7280f47f7c7c2 Retha Corene Armstrong 0 98623 Huels Manor\nJasttown, DE 31611 3 349 clementina29 cdaf6c3483f19e2253659a40a3aab786a3390f78 Darius Ethyl Reichel 0 99296 Keeling Courts\nNorth Audreanne, IL 28272 CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `date_of_registration` DATETIME, `date_of_latest_logon` DATETIME, `login_name` VARCHAR(40), `password` VARCHAR(10), `personal_name` VARCHAR(40), `middle_name` VARCHAR(40), `family_name` VARCHAR(40) ) 3 rows from Students table: student_id date_of_registration date_of_latest_logon login_name password personal_name middle_name family_name 1 2015-07-22 13:32:35 2017-10-17 22:52:26 annamae.hoppe db8765bb6f Wilson Aubrey Ward 2 2015-07-02 00:21:42 2017-06-24 22:16:27 wmiller 35faf8182a Karson Luella Jaskolski 3 2015-10-11 03:23:27 2018-03-10 23:22:23 ahartmann 8e064ec4e6 Mariela Brandt Legros CREATE TABLE `Subjects` ( `subject_id` INTEGER PRIMARY KEY, `subject_name` VARCHAR(120) ) 3 rows from Subjects table: subject_id subject_name 1 Computer Science 2 Arts 3 Language CREATE TABLE `Courses` ( `course_id` INTEGER PRIMARY KEY, `author_id` INTEGER NOT NULL, `subject_id` INTEGER NOT NULL, `course_name` VARCHAR(120), `course_description` VARCHAR(255), FOREIGN KEY (`author_id` ) REFERENCES `Course_Authors_and_Tutors`(`author_id` ), FOREIGN KEY (`subject_id` ) REFERENCES `Subjects`(`subject_id` ) ) 3 rows from Courses table: course_id author_id subject_id course_name course_description 1 8 1 database database 2 6 1 advanced database advanced database 3 15 1 operating system operating system CREATE TABLE `Student_Course_Enrolment` ( `registration_id` INTEGER PRIMARY KEY, `student_id` INTEGER NOT NULL, `course_id` INTEGER NOT NULL, `date_of_enrolment` DATETIME NOT NULL, `date_of_completion` DATETIME NOT NULL, FOREIGN KEY (`course_id` ) REFERENCES `Courses`(`course_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ) 3 rows from Student_Course_Enrolment table: registration_id student_id course_id date_of_enrolment date_of_completion 1 11 2 2017-10-09 07:09:02 2018-02-26 07:48:52 2 15 4 2017-11-13 12:49:33 2018-03-04 01:24:56 3 10 8 2017-10-17 13:50:40 2018-03-22 02:53:01 CREATE TABLE `Student_Tests_Taken` ( `registration_id` INTEGER NOT NULL, `date_test_taken` DATETIME NOT NULL, `test_result` VARCHAR(255), FOREIGN KEY (`registration_id` ) REFERENCES `Student_Course_Enrolment`(`registration_id` ) ) 3 rows from Student_Tests_Taken table: registration_id date_test_taken test_result 12 2018-03-25 03:27:16 Fail 10 2018-03-25 21:50:22 Pass 7 2018-03-21 00:32:25 Pass
insurance_policies
Which claims caused more than 2 settlements or have the maximum claim value? List the date the claim was made and the claim id.
SELECT T1.Date_Claim_Made , T1.Claim_id FROM Claims AS T1 JOIN Settlements AS T2 ON T1.Claim_id = T2.Claim_id GROUP BY T1.Claim_id HAVING count(*) > 2 UNION SELECT T1.Date_Claim_Made , T1.Claim_id FROM Claims AS T1 JOIN Settlements AS T2 ON T1.Claim_id = T2.Claim_id WHERE T1.Amount_Claimed = ( SELECT max(Amount_Claimed) FROM Claims )
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Find the claims that led to more than two settlements or have the maximum claim value. For each of them, return the date the claim was made and the id of the claim.
SELECT T1.Date_Claim_Made , T1.Claim_id FROM Claims AS T1 JOIN Settlements AS T2 ON T1.Claim_id = T2.Claim_id GROUP BY T1.Claim_id HAVING count(*) > 2 UNION SELECT T1.Date_Claim_Made , T1.Claim_id FROM Claims AS T1 JOIN Settlements AS T2 ON T1.Claim_id = T2.Claim_id WHERE T1.Amount_Claimed = ( SELECT max(Amount_Claimed) FROM Claims )
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Which customer had at least 2 policies but did not file any claims? List the customer details and id.
SELECT T1.customer_details , T1.customer_id FROM Customers AS T1 JOIN Customer_Policies AS T2 ON T1.Customer_id = T2.customer_id GROUP BY T1.customer_id HAVING count(*) >= 2 EXCEPT SELECT T1.customer_details , T1.customer_id FROM Customers AS T1 JOIN Customer_Policies AS T2 ON T1.Customer_id = T2.customer_id JOIN Claims AS T3 ON T2.policy_id = T3.policy_id
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Give me the the customer details and id for the customers who had two or more policies but did not file any claims.
SELECT T1.customer_details , T1.customer_id FROM Customers AS T1 JOIN Customer_Policies AS T2 ON T1.Customer_id = T2.customer_id GROUP BY T1.customer_id HAVING count(*) >= 2 EXCEPT SELECT T1.customer_details , T1.customer_id FROM Customers AS T1 JOIN Customer_Policies AS T2 ON T1.Customer_id = T2.customer_id JOIN Claims AS T3 ON T2.policy_id = T3.policy_id
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
List the method, date and amount of all the payments, in ascending order of date.
SELECT Payment_Method_Code , Date_Payment_Made , Amount_Payment FROM Payments ORDER BY Date_Payment_Made ASC
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
What are the method, date and amount of each payment? Sort the list in ascending order of date.
SELECT Payment_Method_Code , Date_Payment_Made , Amount_Payment FROM Payments ORDER BY Date_Payment_Made ASC
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Among all the claims, what is the settlement amount of the claim with the largest claim amount? List both the settlement amount and claim amount.
SELECT Amount_Settled , Amount_Claimed FROM Claims ORDER BY Amount_Claimed DESC LIMIT 1
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Find the settlement amount of the claim with the largest claim amount. Show both the settlement amount and claim amount.
SELECT Amount_Settled , Amount_Claimed FROM Claims ORDER BY Amount_Claimed DESC LIMIT 1
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Among all the claims, what is the amount claimed in the claim with the least amount settled? List both the settlement amount and claim amount.
SELECT Amount_Settled , Amount_Claimed FROM Claims ORDER BY Amount_Settled ASC LIMIT 1
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Find the claimed amount in the claim with the least amount settled. Show both the settlement amount and claim amount.
SELECT Amount_Settled , Amount_Claimed FROM Claims ORDER BY Amount_Settled ASC LIMIT 1
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Among all the claims, which claims have a claimed amount larger than the average? List the date the claim was made and the date it was settled.
SELECT Date_Claim_Made , Date_Claim_Settled FROM Claims WHERE Amount_Claimed > ( SELECT avg(Amount_Claimed) FROM Claims )
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Give me the claim date, settlement date for all the claims whose claimed amount is larger than the average.
SELECT Date_Claim_Made , Date_Claim_Settled FROM Claims WHERE Amount_Claimed > ( SELECT avg(Amount_Claimed) FROM Claims )
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Among all the claims, which settlements have a claimed amount that is no more than the average? List the claim start date.
SELECT Date_Claim_Made FROM Claims WHERE Amount_Settled <= ( SELECT avg(Amount_Settled) FROM Claims )
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Return the claim start date for the claims whose claimed amount is no more than the average
SELECT Date_Claim_Made FROM Claims WHERE Amount_Settled <= ( SELECT avg(Amount_Settled) FROM Claims )
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
How many settlements does each claim correspond to? List the claim id and the number of settlements.
SELECT T1.Claim_id , count(*) FROM Claims AS T1 JOIN Settlements AS T2 ON T1.claim_id = T2.claim_id GROUP BY T1.claim_id
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Find the number of settlements each claim corresponds to. Show the number together with the claim id.
SELECT T1.Claim_id , count(*) FROM Claims AS T1 JOIN Settlements AS T2 ON T1.claim_id = T2.claim_id GROUP BY T1.claim_id
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Which claim incurred the most number of settlements? List the claim id, the date the claim was made, and the number.
SELECT T1.claim_id , T1.date_claim_made , count(*) FROM Claims AS T1 JOIN Settlements AS T2 ON T1.claim_id = T2.claim_id GROUP BY T1.claim_id ORDER BY count(*) DESC LIMIT 1
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Find the claim id and claim date of the claim that incurred the most settlement count. Also tell me the count.
SELECT T1.claim_id , T1.date_claim_made , count(*) FROM Claims AS T1 JOIN Settlements AS T2 ON T1.claim_id = T2.claim_id GROUP BY T1.claim_id ORDER BY count(*) DESC LIMIT 1
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
How many settlements were made on the claim with the most recent claim settlement date? List the number and the claim id.
SELECT count(*) , T1.claim_id FROM Claims AS T1 JOIN Settlements AS T2 ON T1.claim_id = T2.claim_id GROUP BY T1.claim_id ORDER BY T1.Date_Claim_Settled DESC LIMIT 1
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Find the claim id and the number of settlements made for the claim with the most recent settlement date.
SELECT count(*) , T1.claim_id FROM Claims AS T1 JOIN Settlements AS T2 ON T1.claim_id = T2.claim_id GROUP BY T1.claim_id ORDER BY T1.Date_Claim_Settled DESC LIMIT 1
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Of all the claims, what was the earliest date when any claim was made?
SELECT Date_Claim_Made FROM Claims ORDER BY Date_Claim_Made ASC LIMIT 1
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Tell me the the date when the first claim was made.
SELECT Date_Claim_Made FROM Claims ORDER BY Date_Claim_Made ASC LIMIT 1
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
What is the total amount of settlement made for all the settlements?
SELECT sum(Amount_Settled) FROM Settlements
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Compute the total amount of settlement across all the settlements.
SELECT sum(Amount_Settled) FROM Settlements
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Who are the customers that had more than 1 policy? List the customer details and id.
SELECT T1.customer_details , T1.customer_id FROM Customers AS T1 JOIN Customer_Policies AS T2 ON T1.Customer_id = T2.Customer_id GROUP BY T1.customer_id HAVING count(*) > 1
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Find the the customer details and id for the customers who had more than one policy.
SELECT T1.customer_details , T1.customer_id FROM Customers AS T1 JOIN Customer_Policies AS T2 ON T1.Customer_id = T2.Customer_id GROUP BY T1.customer_id HAVING count(*) > 1
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
What are the claim dates and settlement dates of all the settlements?
SELECT Date_Claim_Made , Date_Claim_Settled FROM Settlements
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Tell me the the claim date and settlement date for each settlement case.
SELECT Date_Claim_Made , Date_Claim_Settled FROM Settlements
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
What is the most popular payment method?
SELECT Payment_Method_Code FROM Payments GROUP BY Payment_Method_Code ORDER BY count(*) DESC LIMIT 1
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Which payment method is used the most often?
SELECT Payment_Method_Code FROM Payments GROUP BY Payment_Method_Code ORDER BY count(*) DESC LIMIT 1
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
With which kind of payment method were the least number of payments processed?
SELECT Payment_Method_Code FROM Payments GROUP BY Payment_Method_Code ORDER BY count(*) ASC LIMIT 1
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
What is the payment method that were used the least often?
SELECT Payment_Method_Code FROM Payments GROUP BY Payment_Method_Code ORDER BY count(*) ASC LIMIT 1
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
What is the total amount of payment?
SELECT sum(Amount_Payment) FROM Payments
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Compute the total amount of payment processed.
SELECT sum(Amount_Payment) FROM Payments
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
What are all the distinct details of the customers?
SELECT DISTINCT customer_details FROM Customers
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Return the distinct customer details.
SELECT DISTINCT customer_details FROM Customers
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Which kind of policy type was chosen by the most customers?
SELECT Policy_Type_Code FROM Customer_Policies GROUP BY Policy_Type_Code ORDER BY count(*) DESC LIMIT 1
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Find the policy type the most customers choose.
SELECT Policy_Type_Code FROM Customer_Policies GROUP BY Policy_Type_Code ORDER BY count(*) DESC LIMIT 1
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
How many settlements are there in total?
SELECT count(*) FROM Settlements
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Count the total number of settlements made.
SELECT count(*) FROM Settlements
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Which Payments were processed with Visa? List the payment Id, the date and the amount.
SELECT Payment_ID , Date_Payment_Made , Amount_Payment FROM Payments WHERE Payment_Method_Code = 'Visa'
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Give me the payment Id, the date and the amount for all the payments processed with Visa.
SELECT Payment_ID , Date_Payment_Made , Amount_Payment FROM Payments WHERE Payment_Method_Code = 'Visa'
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
List the details of the customers who do not have any policies.
SELECT customer_details FROM Customers EXCEPT SELECT T1.customer_details FROM Customers AS T1 JOIN Customer_Policies AS T2 ON T1.customer_id = T2.customer_id
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Which customers do not have any policies? Find the details of these customers.
SELECT customer_details FROM Customers EXCEPT SELECT T1.customer_details FROM Customers AS T1 JOIN Customer_Policies AS T2 ON T1.customer_id = T2.customer_id
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
List the date the claim was made, the date it was settled and the amount settled for all the claims which had exactly one settlement.
SELECT T1.claim_id , T1.date_claim_made , T1.Date_Claim_Settled FROM Claims AS T1 JOIN Settlements AS T2 ON T1.Claim_id = T2.Claim_id GROUP BY T1.claim_id HAVING count(*) = 1
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Which claims had exactly one settlement? For each, tell me the the date the claim was made, the date it was settled and the amount settled.
SELECT T1.claim_id , T1.date_claim_made , T1.Date_Claim_Settled FROM Claims AS T1 JOIN Settlements AS T2 ON T1.Claim_id = T2.Claim_id GROUP BY T1.claim_id HAVING count(*) = 1
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
Find the total claimed amount of all the claims.
SELECT sum(Amount_Claimed) FROM Claims
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
insurance_policies
What is total amount claimed summed across all the claims?
SELECT sum(Amount_Claimed) FROM Claims
CREATE TABLE Customers ( Customer_ID INTEGER NOT NULL, Customer_Details VARCHAR(255) NOT NULL, PRIMARY KEY (Customer_ID) ) 3 rows from Customers table: Customer_ID Customer_Details 1 America Jaskolski 2 Ellsworth Paucek 3 Mrs. Hanna Willms CREATE TABLE Customer_Policies ( Policy_ID INTEGER NOT NULL, Customer_ID INTEGER NOT NULL, Policy_Type_Code CHAR(15) NOT NULL, Start_Date DATE, End_Date DATE, PRIMARY KEY (Policy_ID), FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID) ) 3 rows from Customer_Policies table: Policy_ID Customer_ID Policy_Type_Code Start_Date End_Date 119 1 Car 2018-01-21 2017-12-15 141 2 Life 2017-08-21 2017-09-29 143 3 Car 2017-06-16 2017-12-09 CREATE TABLE Claims ( Claim_ID INTEGER NOT NULL, Policy_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, PRIMARY KEY (Claim_ID), FOREIGN KEY (Policy_ID) REFERENCES Customer_Policies (Policy_ID) ) 3 rows from Claims table: Claim_ID Policy_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled 143 744 2017-03-11 2017-11-03 43884 1085 423 552 2016-08-12 2018-01-27 79134 1724 442 473 2017-02-24 2018-01-21 70088 1189 CREATE TABLE Settlements ( Settlement_ID INTEGER NOT NULL, Claim_ID INTEGER NOT NULL, Date_Claim_Made DATE, Date_Claim_Settled DATE, Amount_Claimed INTEGER, Amount_Settled INTEGER, Customer_Policy_ID INTEGER NOT NULL, PRIMARY KEY (Settlement_ID), FOREIGN KEY (Claim_ID) REFERENCES Claims (Claim_ID) ) 3 rows from Settlements table: Settlement_ID Claim_ID Date_Claim_Made Date_Claim_Settled Amount_Claimed Amount_Settled Customer_Policy_ID 357 486 2018-08-07 2018-01-16 38543 1181 515 412 621 2017-08-27 2018-02-04 57669 1427 617 476 801 2016-09-05 2018-03-02 30954 1805 943 CREATE TABLE Payments ( Payment_ID INTEGER NOT NULL, Settlement_ID INTEGER NOT NULL, Payment_Method_Code VARCHAR(255), Date_Payment_Made DATE, Amount_Payment INTEGER, PRIMARY KEY (Payment_ID), FOREIGN KEY (Settlement_ID) REFERENCES Settlements (Settlement_ID) ) 3 rows from Payments table: Payment_ID Settlement_ID Payment_Method_Code Date_Payment_Made Amount_Payment 384 516 MasterCard 2018-02-16 241730 435 476 MasterCard 2017-05-28 448613 484 516 MasterCard 2017-06-24 456098
hospital_1
Which department has the largest number of employees?
SELECT name FROM department GROUP BY departmentID ORDER BY count(departmentID) DESC LIMIT 1;
CREATE TABLE Physician ( EmployeeID INTEGER NOT NULL, Name VARCHAR(30) NOT NULL, Position VARCHAR(30) NOT NULL, SSN INTEGER NOT NULL, CONSTRAINT pk_physician PRIMARY KEY(EmployeeID) ) 3 rows from Physician table: EmployeeID Name Position SSN 1 John Dorian Staff Internist 111111111 2 Elliot Reid Attending Physician 222222222 3 Christopher Turk Surgical Attending Physician 333333333 CREATE TABLE Department ( DepartmentID INTEGER NOT NULL, Name VARCHAR(30) NOT NULL, Head INTEGER NOT NULL, CONSTRAINT pk_Department PRIMARY KEY(DepartmentID), CONSTRAINT fk_Department_Physician_EmployeeID FOREIGN KEY(Head) REFERENCES Physician(EmployeeID) ) 3 rows from Department table: DepartmentID Name Head 1 General Medicine 4 2 Surgery 7 3 Psychiatry 9 CREATE TABLE Affiliated_With ( Physician INTEGER NOT NULL, Department INTEGER NOT NULL, PrimaryAffiliation BOOLEAN NOT NULL, CONSTRAINT fk_Affiliated_With_Physician_EmployeeID FOREIGN KEY(Physician) REFERENCES Physician(EmployeeID), CONSTRAINT fk_Affiliated_With_Department_DepartmentID FOREIGN KEY(Department) REFERENCES Department(DepartmentID), PRIMARY KEY(Physician, Department) ) 3 rows from Affiliated_With table: Physician Department PrimaryAffiliation 1 1 1 2 1 1 3 1 0 CREATE TABLE Procedures ( Code INTEGER PRIMARY KEY NOT NULL, Name VARCHAR(30) NOT NULL, Cost REAL NOT NULL ) 3 rows from Procedures table: Code Name Cost 1 Reverse Rhinopodoplasty 1500.0 2 Obtuse Pyloric Recombobulation 3750.0 3 Folded Demiophtalmectomy 4500.0 CREATE TABLE Trained_In ( Physician INTEGER NOT NULL, Treatment INTEGER NOT NULL, CertificationDate DATETIME NOT NULL, CertificationExpires DATETIME NOT NULL, CONSTRAINT fk_Trained_In_Physician_EmployeeID FOREIGN KEY(Physician) REFERENCES Physician(EmployeeID), CONSTRAINT fk_Trained_In_Procedures_Code FOREIGN KEY(Treatment) REFERENCES Procedures(Code), PRIMARY KEY(Physician, Treatment) ) 3 rows from Trained_In table: Physician Treatment CertificationDate CertificationExpires 3 1 2008-01-01 2008-12-31 3 2 2008-01-01 2008-12-31 3 5 2008-01-01 2008-12-31 CREATE TABLE Patient ( SSN INTEGER PRIMARY KEY NOT NULL, Name VARCHAR(30) NOT NULL, Address VARCHAR(30) NOT NULL, Phone VARCHAR(30) NOT NULL, InsuranceID INTEGER NOT NULL, PCP INTEGER NOT NULL, CONSTRAINT fk_Patient_Physician_EmployeeID FOREIGN KEY(PCP) REFERENCES Physician(EmployeeID) ) 3 rows from Patient table: SSN Name Address Phone InsuranceID PCP 100000001 John Smith 42 Foobar Lane 555-0256 68476213 1 100000002 Grace Ritchie 37 Snafu Drive 555-0512 36546321 2 100000003 Random J. Patient 101 Omgbbq Street 555-1204 65465421 2 CREATE TABLE Nurse ( EmployeeID INTEGER PRIMARY KEY NOT NULL, Name VARCHAR(30) NOT NULL, Position VARCHAR(30) NOT NULL, Registered BOOLEAN NOT NULL, SSN INTEGER NOT NULL ) 3 rows from Nurse table: EmployeeID Name Position Registered SSN 101 Carla Espinosa Head Nurse 1 111111110 102 Laverne Roberts Nurse 1 222222220 103 Paul Flowers Nurse 0 333333330 CREATE TABLE Appointment ( AppointmentID INTEGER PRIMARY KEY NOT NULL, Patient INTEGER NOT NULL, PrepNurse INTEGER, Physician INTEGER NOT NULL, Start DATETIME NOT NULL, End DATETIME NOT NULL, ExaminationRoom TEXT NOT NULL, CONSTRAINT fk_Appointment_Patient_SSN FOREIGN KEY(Patient) REFERENCES Patient(SSN), CONSTRAINT fk_Appointment_Nurse_EmployeeID FOREIGN KEY(PrepNurse) REFERENCES Nurse(EmployeeID), CONSTRAINT fk_Appointment_Physician_EmployeeID FOREIGN KEY(Physician) REFERENCES Physician(EmployeeID) ) 3 rows from Appointment table: AppointmentID Patient PrepNurse Physician Start End ExaminationRoom 13216584 100000001 101 1 2008-04-24 10:00 2008-04-24 11:00 A 26548913 100000002 101 2 2008-04-24 10:00 2008-04-24 11:00 B 36549879 100000001 102 1 2008-04-25 10:00 2008-04-25 11:00 A CREATE TABLE Medication ( Code INTEGER PRIMARY KEY NOT NULL, Name VARCHAR(30) NOT NULL, Brand VARCHAR(30) NOT NULL, Description VARCHAR(30) NOT NULL ) 3 rows from Medication table: Code Name Brand Description 1 Procrastin-X X N/A 2 Thesisin Foo Labs N/A 3 Awakin Bar Laboratories N/A CREATE TABLE Prescribes ( Physician INTEGER NOT NULL, Patient INTEGER NOT NULL, Medication INTEGER NOT NULL, Date DATETIME NOT NULL, Appointment INTEGER, Dose VARCHAR(30) NOT NULL, PRIMARY KEY(Physician, Patient, Medication, Date), CONSTRAINT fk_Prescribes_Physician_EmployeeID FOREIGN KEY(Physician) REFERENCES Physician(EmployeeID), CONSTRAINT fk_Prescribes_Patient_SSN FOREIGN KEY(Patient) REFERENCES Patient(SSN), CONSTRAINT fk_Prescribes_Medication_Code FOREIGN KEY(Medication) REFERENCES Medication(Code), CONSTRAINT fk_Prescribes_Appointment_AppointmentID FOREIGN KEY(Appointment) REFERENCES Appointment(AppointmentID) ) 3 rows from Prescribes table: Physician Patient Medication Date Appointment Dose 1 100000001 1 2008-04-24 10:47 13216584.0 5 9 100000004 2 2008-04-27 10:53 86213939.0 10 9 100000004 2 2008-04-30 16:53 NaN 5 CREATE TABLE Block ( BlockFloor INTEGER NOT NULL, BlockCode INTEGER NOT NULL, PRIMARY KEY(BlockFloor, BlockCode) ) 3 rows from Block table: BlockFloor BlockCode 1 1 1 2 1 3 CREATE TABLE Room ( RoomNumber INTEGER PRIMARY KEY NOT NULL, RoomType VARCHAR(30) NOT NULL, BlockFloor INTEGER NOT NULL, BlockCode INTEGER NOT NULL, Unavailable BOOLEAN NOT NULL, CONSTRAINT fk_Room_Block_PK FOREIGN KEY(BlockFloor, BlockCode) REFERENCES Block(BlockFloor, BlockCode) ) 3 rows from Room table: RoomNumber RoomType BlockFloor BlockCode Unavailable 101 Single 1 1 0 102 Single 1 1 0 103 Single 1 1 0 CREATE TABLE On_Call ( Nurse INTEGER NOT NULL, BlockFloor INTEGER NOT NULL, BlockCode INTEGER NOT NULL, OnCallStart DATETIME NOT NULL, OnCallEnd DATETIME NOT NULL, PRIMARY KEY(Nurse, BlockFloor, BlockCode, OnCallStart, OnCallEnd), CONSTRAINT fk_OnCall_Nurse_EmployeeID FOREIGN KEY(Nurse) REFERENCES Nurse(EmployeeID), CONSTRAINT fk_OnCall_Block_Floor FOREIGN KEY(BlockFloor, BlockCode) REFERENCES Block(BlockFloor, BlockCode) ) 3 rows from On_Call table: Nurse BlockFloor BlockCode OnCallStart OnCallEnd 101 1 1 2008-11-04 11:00 2008-11-04 19:00 101 1 2 2008-11-04 11:00 2008-11-04 19:00 102 1 3 2008-11-04 11:00 2008-11-04 19:00 CREATE TABLE Stay ( StayID INTEGER PRIMARY KEY NOT NULL, Patient INTEGER NOT NULL, Room INTEGER NOT NULL, StayStart DATETIME NOT NULL, StayEnd DATETIME NOT NULL, CONSTRAINT fk_Stay_Patient_SSN FOREIGN KEY(Patient) REFERENCES Patient(SSN), CONSTRAINT fk_Stay_Room_Number FOREIGN KEY(Room) REFERENCES Room(RoomNumber) ) 3 rows from Stay table: StayID Patient Room StayStart StayEnd 3215 100000001 111 2008-05-01 2008-05-04 3216 100000003 123 2008-05-03 2008-05-14 3217 100000004 112 2008-05-02 2008-05-03 CREATE TABLE Undergoes ( Patient INTEGER NOT NULL, Procedures INTEGER NOT NULL, Stay INTEGER NOT NULL, DateUndergoes DATETIME NOT NULL, Physician INTEGER NOT NULL, AssistingNurse INTEGER, PRIMARY KEY(Patient, Procedures, Stay, DateUndergoes), CONSTRAINT fk_Undergoes_Patient_SSN FOREIGN KEY(Patient) REFERENCES Patient(SSN), CONSTRAINT fk_Undergoes_Procedures_Code FOREIGN KEY(Procedures) REFERENCES Procedures(Code), CONSTRAINT fk_Undergoes_Stay_StayID FOREIGN KEY(Stay) REFERENCES Stay(StayID), CONSTRAINT fk_Undergoes_Physician_EmployeeID FOREIGN KEY(Physician) REFERENCES Physician(EmployeeID), CONSTRAINT fk_Undergoes_Nurse_EmployeeID FOREIGN KEY(AssistingNurse) REFERENCES Nurse(EmployeeID) ) 3 rows from Undergoes table: Patient Procedures Stay DateUndergoes Physician AssistingNurse 100000001 6 3215 2008-05-02 3 101 100000001 2 3215 2008-05-03 7 101 100000004 1 3217 2008-05-07 3 102
hospital_1
Find the department with the most employees.
SELECT name FROM department GROUP BY departmentID ORDER BY count(departmentID) DESC LIMIT 1;
CREATE TABLE Physician ( EmployeeID INTEGER NOT NULL, Name VARCHAR(30) NOT NULL, Position VARCHAR(30) NOT NULL, SSN INTEGER NOT NULL, CONSTRAINT pk_physician PRIMARY KEY(EmployeeID) ) 3 rows from Physician table: EmployeeID Name Position SSN 1 John Dorian Staff Internist 111111111 2 Elliot Reid Attending Physician 222222222 3 Christopher Turk Surgical Attending Physician 333333333 CREATE TABLE Department ( DepartmentID INTEGER NOT NULL, Name VARCHAR(30) NOT NULL, Head INTEGER NOT NULL, CONSTRAINT pk_Department PRIMARY KEY(DepartmentID), CONSTRAINT fk_Department_Physician_EmployeeID FOREIGN KEY(Head) REFERENCES Physician(EmployeeID) ) 3 rows from Department table: DepartmentID Name Head 1 General Medicine 4 2 Surgery 7 3 Psychiatry 9 CREATE TABLE Affiliated_With ( Physician INTEGER NOT NULL, Department INTEGER NOT NULL, PrimaryAffiliation BOOLEAN NOT NULL, CONSTRAINT fk_Affiliated_With_Physician_EmployeeID FOREIGN KEY(Physician) REFERENCES Physician(EmployeeID), CONSTRAINT fk_Affiliated_With_Department_DepartmentID FOREIGN KEY(Department) REFERENCES Department(DepartmentID), PRIMARY KEY(Physician, Department) ) 3 rows from Affiliated_With table: Physician Department PrimaryAffiliation 1 1 1 2 1 1 3 1 0 CREATE TABLE Procedures ( Code INTEGER PRIMARY KEY NOT NULL, Name VARCHAR(30) NOT NULL, Cost REAL NOT NULL ) 3 rows from Procedures table: Code Name Cost 1 Reverse Rhinopodoplasty 1500.0 2 Obtuse Pyloric Recombobulation 3750.0 3 Folded Demiophtalmectomy 4500.0 CREATE TABLE Trained_In ( Physician INTEGER NOT NULL, Treatment INTEGER NOT NULL, CertificationDate DATETIME NOT NULL, CertificationExpires DATETIME NOT NULL, CONSTRAINT fk_Trained_In_Physician_EmployeeID FOREIGN KEY(Physician) REFERENCES Physician(EmployeeID), CONSTRAINT fk_Trained_In_Procedures_Code FOREIGN KEY(Treatment) REFERENCES Procedures(Code), PRIMARY KEY(Physician, Treatment) ) 3 rows from Trained_In table: Physician Treatment CertificationDate CertificationExpires 3 1 2008-01-01 2008-12-31 3 2 2008-01-01 2008-12-31 3 5 2008-01-01 2008-12-31 CREATE TABLE Patient ( SSN INTEGER PRIMARY KEY NOT NULL, Name VARCHAR(30) NOT NULL, Address VARCHAR(30) NOT NULL, Phone VARCHAR(30) NOT NULL, InsuranceID INTEGER NOT NULL, PCP INTEGER NOT NULL, CONSTRAINT fk_Patient_Physician_EmployeeID FOREIGN KEY(PCP) REFERENCES Physician(EmployeeID) ) 3 rows from Patient table: SSN Name Address Phone InsuranceID PCP 100000001 John Smith 42 Foobar Lane 555-0256 68476213 1 100000002 Grace Ritchie 37 Snafu Drive 555-0512 36546321 2 100000003 Random J. Patient 101 Omgbbq Street 555-1204 65465421 2 CREATE TABLE Nurse ( EmployeeID INTEGER PRIMARY KEY NOT NULL, Name VARCHAR(30) NOT NULL, Position VARCHAR(30) NOT NULL, Registered BOOLEAN NOT NULL, SSN INTEGER NOT NULL ) 3 rows from Nurse table: EmployeeID Name Position Registered SSN 101 Carla Espinosa Head Nurse 1 111111110 102 Laverne Roberts Nurse 1 222222220 103 Paul Flowers Nurse 0 333333330 CREATE TABLE Appointment ( AppointmentID INTEGER PRIMARY KEY NOT NULL, Patient INTEGER NOT NULL, PrepNurse INTEGER, Physician INTEGER NOT NULL, Start DATETIME NOT NULL, End DATETIME NOT NULL, ExaminationRoom TEXT NOT NULL, CONSTRAINT fk_Appointment_Patient_SSN FOREIGN KEY(Patient) REFERENCES Patient(SSN), CONSTRAINT fk_Appointment_Nurse_EmployeeID FOREIGN KEY(PrepNurse) REFERENCES Nurse(EmployeeID), CONSTRAINT fk_Appointment_Physician_EmployeeID FOREIGN KEY(Physician) REFERENCES Physician(EmployeeID) ) 3 rows from Appointment table: AppointmentID Patient PrepNurse Physician Start End ExaminationRoom 13216584 100000001 101 1 2008-04-24 10:00 2008-04-24 11:00 A 26548913 100000002 101 2 2008-04-24 10:00 2008-04-24 11:00 B 36549879 100000001 102 1 2008-04-25 10:00 2008-04-25 11:00 A CREATE TABLE Medication ( Code INTEGER PRIMARY KEY NOT NULL, Name VARCHAR(30) NOT NULL, Brand VARCHAR(30) NOT NULL, Description VARCHAR(30) NOT NULL ) 3 rows from Medication table: Code Name Brand Description 1 Procrastin-X X N/A 2 Thesisin Foo Labs N/A 3 Awakin Bar Laboratories N/A CREATE TABLE Prescribes ( Physician INTEGER NOT NULL, Patient INTEGER NOT NULL, Medication INTEGER NOT NULL, Date DATETIME NOT NULL, Appointment INTEGER, Dose VARCHAR(30) NOT NULL, PRIMARY KEY(Physician, Patient, Medication, Date), CONSTRAINT fk_Prescribes_Physician_EmployeeID FOREIGN KEY(Physician) REFERENCES Physician(EmployeeID), CONSTRAINT fk_Prescribes_Patient_SSN FOREIGN KEY(Patient) REFERENCES Patient(SSN), CONSTRAINT fk_Prescribes_Medication_Code FOREIGN KEY(Medication) REFERENCES Medication(Code), CONSTRAINT fk_Prescribes_Appointment_AppointmentID FOREIGN KEY(Appointment) REFERENCES Appointment(AppointmentID) ) 3 rows from Prescribes table: Physician Patient Medication Date Appointment Dose 1 100000001 1 2008-04-24 10:47 13216584.0 5 9 100000004 2 2008-04-27 10:53 86213939.0 10 9 100000004 2 2008-04-30 16:53 NaN 5 CREATE TABLE Block ( BlockFloor INTEGER NOT NULL, BlockCode INTEGER NOT NULL, PRIMARY KEY(BlockFloor, BlockCode) ) 3 rows from Block table: BlockFloor BlockCode 1 1 1 2 1 3 CREATE TABLE Room ( RoomNumber INTEGER PRIMARY KEY NOT NULL, RoomType VARCHAR(30) NOT NULL, BlockFloor INTEGER NOT NULL, BlockCode INTEGER NOT NULL, Unavailable BOOLEAN NOT NULL, CONSTRAINT fk_Room_Block_PK FOREIGN KEY(BlockFloor, BlockCode) REFERENCES Block(BlockFloor, BlockCode) ) 3 rows from Room table: RoomNumber RoomType BlockFloor BlockCode Unavailable 101 Single 1 1 0 102 Single 1 1 0 103 Single 1 1 0 CREATE TABLE On_Call ( Nurse INTEGER NOT NULL, BlockFloor INTEGER NOT NULL, BlockCode INTEGER NOT NULL, OnCallStart DATETIME NOT NULL, OnCallEnd DATETIME NOT NULL, PRIMARY KEY(Nurse, BlockFloor, BlockCode, OnCallStart, OnCallEnd), CONSTRAINT fk_OnCall_Nurse_EmployeeID FOREIGN KEY(Nurse) REFERENCES Nurse(EmployeeID), CONSTRAINT fk_OnCall_Block_Floor FOREIGN KEY(BlockFloor, BlockCode) REFERENCES Block(BlockFloor, BlockCode) ) 3 rows from On_Call table: Nurse BlockFloor BlockCode OnCallStart OnCallEnd 101 1 1 2008-11-04 11:00 2008-11-04 19:00 101 1 2 2008-11-04 11:00 2008-11-04 19:00 102 1 3 2008-11-04 11:00 2008-11-04 19:00 CREATE TABLE Stay ( StayID INTEGER PRIMARY KEY NOT NULL, Patient INTEGER NOT NULL, Room INTEGER NOT NULL, StayStart DATETIME NOT NULL, StayEnd DATETIME NOT NULL, CONSTRAINT fk_Stay_Patient_SSN FOREIGN KEY(Patient) REFERENCES Patient(SSN), CONSTRAINT fk_Stay_Room_Number FOREIGN KEY(Room) REFERENCES Room(RoomNumber) ) 3 rows from Stay table: StayID Patient Room StayStart StayEnd 3215 100000001 111 2008-05-01 2008-05-04 3216 100000003 123 2008-05-03 2008-05-14 3217 100000004 112 2008-05-02 2008-05-03 CREATE TABLE Undergoes ( Patient INTEGER NOT NULL, Procedures INTEGER NOT NULL, Stay INTEGER NOT NULL, DateUndergoes DATETIME NOT NULL, Physician INTEGER NOT NULL, AssistingNurse INTEGER, PRIMARY KEY(Patient, Procedures, Stay, DateUndergoes), CONSTRAINT fk_Undergoes_Patient_SSN FOREIGN KEY(Patient) REFERENCES Patient(SSN), CONSTRAINT fk_Undergoes_Procedures_Code FOREIGN KEY(Procedures) REFERENCES Procedures(Code), CONSTRAINT fk_Undergoes_Stay_StayID FOREIGN KEY(Stay) REFERENCES Stay(StayID), CONSTRAINT fk_Undergoes_Physician_EmployeeID FOREIGN KEY(Physician) REFERENCES Physician(EmployeeID), CONSTRAINT fk_Undergoes_Nurse_EmployeeID FOREIGN KEY(AssistingNurse) REFERENCES Nurse(EmployeeID) ) 3 rows from Undergoes table: Patient Procedures Stay DateUndergoes Physician AssistingNurse 100000001 6 3215 2008-05-02 3 101 100000001 2 3215 2008-05-03 7 101 100000004 1 3217 2008-05-07 3 102