Homework 3
Contents
Instructions
This homework should be uploaded to Canvas by 11:59pm on Sunday, October 12. All submissions should be in PDF format (if you use Word, just 'PDF' in the 'Save as' dialog). Be sure to list who you've worked with, if anyone.
This assignment uses the PostgreSQL database on Joust. I will be checking everyone's PostgreSQL databases, so make sure you actually carry out these steps.
Questions
1. (10 pts.) Suppose you have the following relations:
EmployeeID | LastName | FirstName |
---|---|---|
1 | Jones | Janet |
2 | Smith | John |
3 | Jackson | George |
4 | Miller | Lou |
EmployeeID | PositionTitle | PositionLevel |
---|---|---|
1 | Engineer | II |
2 | Engineer | I |
3 | Manager | III |
4 | Manager | I |
PositionTitle | PositionLevel | Base |
---|---|---|
Engineer | I | 50000 |
Engineer | II | 55000 |
Engineer | III | 60000 |
Manager | I | 60000 |
Manager | II | 65000 |
Manager | III | 75000 |
EmployeeID | Bonus |
---|---|
2 | 2500 |
4 | 4500 |
Log into Joust and enter into the PostgreSQL shell (psql
). Create
a new database called hw3 and create each of the tables above. For this question, submit the SQL statement you used to create them
2. (5 pts.) In the PostgreSQL shell, enter the SQL statements to enter all of the data shown in the tables above. For this question, submit those SQL statements.
3. (5pts.) In the PostgreSQL shell, enter the SQL statement to find all employees receiving a bonus. Submit the command and the results.
4. (10 pts.) In the PostgreSQL shell, enter the SQL statement to find all position titles that have at least one level with a base salary greater than $60,000. Submit the command and the results.
5. (10 pts.) Convert the following expression to SQL and enter it in the PostgresQL shell. Submit the SQL statement along with the output.
$$ {\large\pi}_{\textrm{EmployeeID}} \left( \textrm{Bonuses} \bowtie \left( {\large\sigma}_{\textrm{Base} < 60000} \left(\textrm{Positions} \bowtie \textrm{SalaryBases}\right) \right)\right)$$6. (10 pts.) Convert the following expression to SQL and enter it in the PostgresQL shell. Submit the SQL statement along with the output.
$$ {\large\pi}_{\textrm{PositionTitle}} \left( {\large\sigma}_{\textrm{Base} < 60000} \textrm{SalarayBases} \cap {\large\sigma}_{\textrm{Base} > 54000} \textrm{SalarayBases} \right)$$ (Back to top) (Back to top)