Question: For the hw2 database, write a SQL query to find all sections of courses with 3 units for term 5 of 2021. Your query should
For the hw2 database, write a SQL query to find all sections of courses with 3 units for term 5 of 2021. Your query should be based on the design of the tables, not the sample data. Don't hard-code the query!
--------------------------------------//-------------------------------------------
hw2 database:
create.sql
-- represents college departments
CREATE TABLE solution.department (
id bigserial primary key ,
name varchar(50) not null,
email varchar(50),
building varchar(50) not null,
room varchar(20) not null
);
-- represents courses offered by college departments
CREATE TABLE solution.course (
id bigserial primary key,
name varchar(255) not null,
dept bigint references solution.department not null,
units int not null
);
-- sections of these courses
CREATE TABLE solution.section (
id bigserial primary key,
course bigint references solution.course not null,
term int not null,
yr int not null,
secNum char(2) not null default '01' -- char because lab sections often use letters
);
-----------------------------//--------------------------------------------
insert.sql
-- insert departments
insert into solution.department (name, email, building, room) values ('English', null, 'Music', '2579');
insert into solution.department (name, email, building, room) values ('Computer Science', 'cs@csueastbay.edu', 'Student and Faculty Support', '570');
insert into solution.department (name, email, building, room) values ('Chemistry', 'chem@csueastbay.edu', 'Science', 'North 431');
-- insert some courses
insert into solution.course (name, dept, units) values ('College Writing: Stretch I', 1, 3);
insert into solution.course (name, dept, units) values ('College Writing Lab', 1, 1);
insert into solution.course (name, dept, units) values ('Database Architecture', 2, 3);
insert into solution.course (name, dept, units) values ('Computer Graphics', 2, 3);
insert into solution.course (name, dept, units) values ('Intro to College Chemistry', 3, 3);
-- insert some sections
insert into solution.section (course, term, yr, secnum) values (1, 9, 2020, '01');
insert into solution.section (course, term, yr, secnum) values (1, 5, 2021, '01');
insert into solution.section (course, term, yr, secnum) values (1, 5, 2021, '02');
insert into solution.section (course, term, yr, secnum) values (2, 9, 2020, '01');
insert into solution.section (course, term, yr, secnum) values (2, 5, 2021, '01');
insert into solution.section (course, term, yr, secnum) values (2, 5, 2021, '02');
insert into solution.section (course, term, yr, secnum) values (3, 5, 2021, '01');
insert into solution.section (course, term, yr, secnum) values (3, 5, 2021, '02');
insert into solution.section (course, term, yr, secnum) values (3, 5, 2021, '03');
insert into solution.section (course, term, yr, secnum) values (3, 9, 2020, '01');
insert into solution.section (course, term, yr, secnum) values (4, 9, 2020, '01');
insert into solution.section (course, term, yr) values (5, 9, 2020);
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
