# w4111/hw2

No description, website, or topics provided.
Switch branches/tags
Nothing to show
Latest commit c2218aa Oct 11, 2018
 Failed to load latest commit information. README.md Oct 11, 2018 hw2_template.pdf Oct 6, 2018 hw2_template.tex Oct 6, 2018

# Homework 2

• Assigned: 10/4
• Due: 10/16 at 10:00AM via Gradescope

Highly recommend to draft your answers using this template (pdf, latex).

## Update logs

### 10.11.2018

• 'You can answer relational algebra with sub steps.' is added to the description of 1. Relational Algebra.

### 10.08.2018

• 'Make sure your SQL can be executed.' is added to the description of 3. SQL.

### 10.05.2018

#### Changed

• 2.5 T1 ⨝T1.A<T2.BB<=2(T2))

• 'Simply answer NULL if you believe the resulting table is empty or there are some errors with the expressions' is added to the description of 2. More Relational Algebra.

## 1. Relational Algebra

(2 points each, 4 points total)

Consider the simplified schema below (primary keys are in bold):

• liquors(lid, name, price, manufacturer)

• sales(month, seller, liquors, county, quantity)

Note: sales(liquors) references liquors(lid), and month is a text field (e.g. January, February).

Construct relational algebra for the following queries, you can answer relational algebra with sub steps:

• Q1: Find the names of liquors that had at least one sale in "Clarke" or "Marshall" counties for the month of November.

• Q2: Find the names of manufacturers that sold at least three different liquors during the month of January in "Marshall" county.

Note: Please use only operators covered in class. For Q2, it might help to think about the "at least two" case and then expand it to "at least three".

## 2. More Relational Algebra

(1 point each, 6 points total)

Simply answer NULL if you believe the resulting table is empty or there are some errors with the expressions.

Given the following tables

T1

A B C
1 x a
2 y b
2 z c

T2

B C D
1 x c
2 y c
3 x a

Write the result table for the relational algebra expressions:

1. πA,B(T1)
2. T1 × πA(T1)
3. T1 ⨝T1.B=T2.C T2
4. T1 − (T1 ∩ T2)
5. T1 ⨝T1.A<T2.BB<=2(T2))
6. T1 ⨝ (σB=c(T2))

## 3. SQL

Write the following relational algebra expressions in SQL. Make sure your SQL can be executed.

Note: You don't need to know the full schema to translate these statements.

1. πname,age(Student)
2. Student × πage(Student)
3. Student ⨝Student.name=Teacher.name Teacher
4. Student − (Student ∩ Teacher)
5. year=2018(Student) )⨝Student.age<Teacher.agename=engene(Teacher))
6. Student ⨝ (σage<=50(Teacher))