Homework 3
Homework 3
CS 632
HOMEWORK 3
40 Points. Due 11/18 in class, at the beginning of class.
Read this carefully. This is more important than the individual questions.
There are NO GROUP HOMEWORKS IN THIS CLASS. YOU NEED TO WORK ALONE.
1) Do not copy code from any other person. You can ask questions and get answers, but
NEVER copy code. Also do not copy and paste English text unless I specifically permit it.
NEVER.
2) SHOW EVERYTHING. Anything you don't show will be automatically assumed as not
done. Don't logically argue that "of course I must have done it." If we don't see it, then it is not
done.
CS 632 homeworks can easily be 50 pages long.
3) There will be no half points. Questions worth 1 point will be graded "all or nothing."
4) NO HANDWRITING ANYWHERE.
5) Points will appear in square brackets.
6) I will discuss ChatGPT use in each homework. You may use it if you understand the result.
7) If you submit up to 1 week later, there will be a late penalty of 8 points subtracted.
If you miss the due date by MORE than a week you will get ZERO points.
8) The Homework has to be submitted as printout AND as ONE uploaded file. It is easier to
grade on paper, but it is easier to check for copying or cheating in an electronic version. I will
provide the upload page before the due date.
9) Make sure that your homework has a NICE LOOKING cover page.
The cover page should show
your name, your email address, and the words: CS 632, Spring 2024, HOMEWORK 3
10) All pages have to be stapled together or be in a folder.
11) Printouts have to be readable. Font size 11 or bigger. This includes screen dumps.
12) Make our lives easier when we grade:
>> All answers have to be in the same order as the questions are given here.
>> Copy and paste the questions, and then put each answer right after the question.
==========================
1) I haven't been happy with many of the answers about the PLUTO data set. Please look
at the data set again and write a one page (double spaced, 11 points Times Roman font)
description of the CONTENT of this data set, and what it is used for (or what it COULD
BE) used for.
Make sure that you structure the page into three or four paragraphs, where each
paragraph focuses more or less on one topic.
[5 points]
a) Perform an inner join of the two tables using the Neighborhood and NTA columns
for the join condition. (Reminder: If a row does not exist in one of the two tables,
then it should not appear in the output at all. Thus the "Typical NYC
Neighborhood" row should disappear.
b) Now redo question a) and combine in it with a create statement so that the result
is captured in a new table Table3.
c) Now write an SQL SELECT statement that will display Table3 but as XML
structure.
This query should select only one column formatted like the XML example given below:
<borough>
<name>Brooklyn</name>
<neighborhood>
<name>Bushwick South</name>
<rent>
<median_rent_2010>894</median_rent_2010>
<median_rent_2016>1206</median_rent_2016>
</rent>
<jobs>
<local_jobs_2010>6906</local_jobs_2010>
<local_jobs_2015>8469</local_jobs_2015>
</jobs>
</neighborhood>
</borough>
This is an example of only one row. Your query should return this XML structure for
every row of Table3. Keep the tag names exactly as shown above.
Show the query output. It is ok if you cannot show the full column because the XML data
is too long but show all the rows.
[8 points]
3) a) Create a new table Table4 with one column that will contain XML data like the output
from question 2. Give this table and column an appropriate name.
b) Insert the rows in the result from question 3) into this table.
Show Table4 with a SELECT statement (again, it is ok to not show the full columns, but
show all the rows).
[6 points]
4) Write a PL/SQL program to select the data using an IMPLICIT cursor from the new table
that you created in question 3. Your table should have the following columns in the order
given below:
a) Borough
b) Neighborhood
c) Median Rent 2010
d) Median Rent 2016
e) Rent Increase
f) Local Jobs 2010
g) Local Jobs 2015
h) Local Job Growth
The values in column ‘Rent Increase’ should be computed from Median Rent 2010 and
Median Rent 2016. You can create a function to do this or compute it in-place, your
choice.
The values in column ‘Local Job Growth’ should be computed from Local Jobs 2010
and Local Jobs 2015. Use the function you created in homework 1 question 6 for this.
It should be formatted like a table with headers specified above and proper spacing
between columns. If you cannot show the complete neighborhood column, show at least
the first 35 characters.
[8 points]
5) For this question you will have to create objects and insert them into a new table. The
following “chest-of-drawers” diagrams describe the structure you need to model with
your objects:
a) Create these two types (if these names conflict with other objects already
existing in your DB, add “_t” at the end of the type name). Show the SQL.
b) Create a new Table5 that contains one column - this column will contain objects
of type Borough. Show the create table SQL statement.
c) Write ONE SQL statement that takes data from Table 1 (the original table that
you created, not the one with XML data) and inserts it into Table5. Do not
manually write the insert statements for each row.
[8 points]
6) Now rewrite the PL/SQL program from question 4. This time, select the data from the
Table5 that you created. The output should look the same as the output in question 4).
You can again use the same functions to calculate the rent increase percentage and job
growth percentage.
[5 points]