Skip to content

HW2: Basic SQL Queries

Due: Tuesday, Sep 10th

Powered by MySQL
Image source: MySQL Logo Downloads

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

Objectives

  • Write queries that use JOIN, GROUP BY, LIMIT, and expressions.
  • Use incremental development to solve problems and look at data.

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 hw2.py (the autograder script) in the same folder as hw2.sql and hw2-sol.txt.
  • In order to run hw2.py, you will need to install MySQL Connector via the command line:
    pip install mysql-connector-python
    
  • If you have trouble with the installation, 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.

World Database

The first database contains information about countries of the world, some of the cities in those countries, and languages spoken in each country. The data is provided by Statistics Finland.

world schema

Employees Database

The second database contains fake data about a company that has a handful of departments and thousands of employees. The data includes about 4 million records in total, including the history of each employee (their departments, job titles, and salaries).

employees schema

Submission

Submit your hw2.sql to the HW2 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 (1 pt each).
  2. Style and formatting of the SQL code (1 pt each).