From 781c7ced42724017f15f2a601521c88d33baec9a Mon Sep 17 00:00:00 2001 From: Shawn Kiernan Date: Wed, 23 Jun 2021 16:53:08 -0500 Subject: [PATCH 1/2] Shawn and Sarah SQL queries solution --- school_queries.sql | 89 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 school_queries.sql diff --git a/school_queries.sql b/school_queries.sql new file mode 100644 index 0000000..30c09dc --- /dev/null +++ b/school_queries.sql @@ -0,0 +1,89 @@ +select * from classes; + +select class_name, credits from classes +where credits > 3; + +select * from classes +where credits % 2 = 0; + +select * from enrollments +join students +on enrollments.student_id = students.id +where students.first_name = 'Tianna' +AND enrollments.grade IS NULL; + +select students.first_name, * from enrollments +join students +on enrollments.student_id = students.id +where students.first_name = 'Tianna' +AND enrollments.grade IS NULL; + +select first_name, class_name from enrollments +join students +on enrollments.student_id = students.id +join classes +on enrollments.class_id = classes.id +where students.first_name = 'Tianna' +AND enrollments.grade IS NULL; + +select first_name, last_name from students +where first_name ilike('%t%') OR +last_name ilike('%t%') AND +birthdate < '1986-01-01'::date; + +select avg(age(current_date, birthdate)) from students; + +select first_name, last_name, line_1, city, state_name, zipcode from addresses +join students on students.address_id = addresses.id +where city ilike ('% %'); + +select avg(credits) from classes; + +select first_name, last_name from students +join enrollments on +students.id = enrollments.student_id +where grade like 'A%'; + +select first_name, sum(credits) from students +join enrollments +on students.id = enrollments.student_id +join classes +on classes.id = enrollments.class_id +group by first_name; + +select first_name, sum(credits) from students +join enrollments +on students.id = enrollments.student_id +join classes +on classes.id = enrollments.class_id +where grade is not null +group by first_name; + +select first_name, class_name from students +join enrollments +on students.id = enrollments.student_id +join classes +on classes.id = enrollments.class_id +group by first_name, class_name +order by 2; + +select first_name, last_name, birthdate from students +where birthdate >= '1982-01-01' AND +birthdate <= '1985-12-31'; + +--insert into enrollments (student_id, class_id) +-- (select student_id from enrollments +-- join students +-- on students.id = enrollments.student_id +-- where last_name = 'Rohan' +-- limit 1) +-- (select class_id from classes +-- join enrollments +-- on classes.id = enrollments.class_id +-- where class_name = 'PHYS 218'); + +-- --INSERT into enrollments (student_id, class_id) +-- SELECT student_id, class_id +-- FROM students, enrollments, classes +-- WHERE students.last_name = 'Rohan' +-- AND classes.class_name = 'PHYS 218'; \ No newline at end of file From b51c40e6945a6a08b9e676d3c70bf1ccdb3e0d99 Mon Sep 17 00:00:00 2001 From: Shawn Kiernan Date: Thu, 24 Jun 2021 11:28:58 -0500 Subject: [PATCH 2/2] Shawn and Sarah sql queries solution --- school_queries.sql | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/school_queries.sql b/school_queries.sql index 30c09dc..589d8d6 100644 --- a/school_queries.sql +++ b/school_queries.sql @@ -86,4 +86,10 @@ birthdate <= '1985-12-31'; -- SELECT student_id, class_id -- FROM students, enrollments, classes -- WHERE students.last_name = 'Rohan' --- AND classes.class_name = 'PHYS 218'; \ No newline at end of file +-- AND classes.class_name = 'PHYS 218'; + +insert into enrollments (student_id, class_id, grade) +select * from + (select id from students where first_name='Andre' and last_name='Rohan' limit 1) x +,(select id from classes where class_name='PHYS 218' limit 1) y +,(select 'A') z; \ No newline at end of file