Skip to content

HW5: Advanced SQL

Due: Thursday, Nov 20th

pgAdmin query tool screenshot
Image source: W3Schools

This is the third of three SQL query assignments. You are given 8 queries to write, along with the expected output. Use pgAdmin to write and test the queries. Be sure to start early—this assignment might take longer than you think.

Objectives

  • Write queries that use set operations (UNION, INTERSECT, EXCEPT).
  • Write queries that use window operations (WINDOW, OVER, PARTITION).

Instructions

  1. Download the provided template. Read and follow the instructions at the top of the file.

  2. Download the solution's output. This is the output that your final queries should produce.

Note: Your SQL file should run without any errors and finish in under two minutes. If any query is taking longer than 15 seconds, you are probably doing something wrong.

Autograder Script – optional, but recommended

Download the autograder script. Gradescope will use this script to test your submission.

  • Run hw5.py (the autograder script) in the same folder as hw5.sql and hw5-sol.txt.
  • If you have trouble getting the script to run, we can help you in class or office hours.
  • Or you can just submit to Gradescope over and over, and the same script will run.
  • We're giving you the autograder script so you don't have to submit so many times.

Part 1: air

The postgres_air database represents airports, flights, passengers, etc. The airports, airline, and route data is based on OpenFlights. Passenger and other data are synthetic. Refer to the Air Diagram for more details.

Part 2: jmudb

jmudb is based on historical enrollment data. There is only one table:

  • enrollment(term, nbr, subject, number, suffix, title, section, room, days, beg_time, end_time, instructor, acad_org, room_cap, enrolled, enrl_cap)

Most of the columns are self-explanatory, except:

  • term is a four-digit number. The first digit is always 1. The next two digits are the year. The last digit is the month (1=Spring, 5=Summer, 8=Fall). So the value 1241 means Spring 2024.

  • nbr is the five-digit course code from MyMadison. Use both term and nbr to uniquely identify a section of a course.

Submission

Submit your hw5.sql to the hw5 assignment on Gradescope.

Your code will first be graded by Gradescope and then by the professor. The grade you receive from Gradescope is the maximum grade that you can receive on the assignment.

After the due date, the professor may manually review your code. At that time, points may be deducted for inelegant code, inappropriate variable names, bad comments, etc.

Gradescope will provide you with hints but might not completely identify the defects in your submission. You are expected to test your own code before submitting.

There is no limit on the number of submissions and no penalty for excessive submissions. Points will be allocated as follows:

Criterion Points Details
Autograder 80 pts Partial Credit Possible
Code Review 20 pts Partial Credit Possible

The code review will include:

  1. The approach you took on each query (10 pts).
  2. Style and formatting of the SQL code (10 pts).