
CISC 7510X
Main
Files
Syllabus
Links
Homeworks
Notes
0001
DB1
Intro
SQL Intro
More SQL
Oracle Primer
MySQL Primer
PostgreSQL Primer
Indexes/Joins
Data Loads
AnalyticFuncs
Grouping Sets
Sample Data
ctsdata.20140211.tar
Stock Ordrs
SQLRunner
|
 |
 |
CISC 7510X (DB1) Homeworks
You should EMAIL me homeworks, alex at theparticle dot com. Start email subject with "CISC 7510X HW#". Homeworks without the subject line risk being deleted and not counted.
CISC 7510 HW# 1 (due by 3rd class;): For the below `store' schema:
product(productid,description,listprice)
customer(customerid,username,fname,lname,street1,street2,city,state,zip)
purchase(purchaseid,purchasetimestamp,customerid)
purchase_items(itemid,purchaseid,productid,quantity,price)
Using SQL, answer these questions (write a SQL query that answers these questions):
- What is the description of productid=42?
- What's the name and address of customerid=42?
- What products did customerid=42 purchase?
- List customers who bought productid=24?
- List customer names who have never puchased anything.
- List product descriptions who have never been purchased by anyone.
- What products were purchased by customers with zip code 10001?
- What percentage of customers have ever purchased productid=42?
- Of customers who purchased productid=42, what percentage also purchased productid=24?
- What is the most popular (purchased most often) product in NY state?
- What is the most popular (purchased most often) product in Tri-state Area? (NJ, NY, CT)
- Who purchased productid=24 prior to July 4th, 2020?
- For each customer, find all products from their last purchase.
- For each customer, find all products from their last 10 purchases.
- Names of customers who have purchased product 42 in the last 3 months.
Also, install PostgreSQL.
CISC 7510 HW# 2 (due by 4th class;): Install PostgreSQL
As a `simple' review of SQL, do `Sample Questions' at the end of: sql2.pdf; For the same database, also answer the following questions:
- Find the company with most employees.
- Find employees who make more than the average salary within their company.
- Find employees who make more than the median salary within their company.
- Find employees whose salary is an outlier (above 2 standard deviations) within their comapny.
- Find employees whose salary is an outlier (above 95th percentile) within their comapny.
- Find the company with the highest number of outlying salaries (your choice which outlier to use).
- Find the company with most non-managing employees.
- Find the company with highest average difference between manager salary and non-manager employee salary.
- Assume that each non-managing employee genererates around 2x their salary in revenue. Managing employees don't directly contribute to revenue. Estimate revenue and ``profit'' for each company (assume profit = revenue - all_salaries).
- Calculate salary skew for profitable (profit > 0) companies from question 9.
Email the query text.
CISC 7510X HW# 3 (due by Nth class;): Write a command line program to "join" .csv files. Use any programming language you're comfortable with (Python suggested). Your program should work similarly to the unix "join" utility (google for it). Unlike the unix join, your program will not require files to be sorted on the key. Your program must also accept the "type" of join to use---merge join, inner loop join, or hash join, etc. Assume that first column is the join key---or you can accept the column number as paramater (like unix join command).
Do not use libraries with join-capabilities (e.g. Pandas, Dataset, or pass your files to unix "join" command, etc. that defeats the purpose of this homework.). Use lists, hashes, your own data-structures, etc., not a library that's essentially a mini-database. Test your program on "large" files (e.g. make sure it wouldn't blow up on one-million-records [e.g. do not store everything in memory], etc.)
Submit source code for the program.
Also... load all files in ctsdata.20140211.tar (link on the left) into Oracle or Postgres (or whichever works for you). The format of these files is: cts(tdate,symbol,open,high,low,close,volume), splits(tdate,symbol,post,pre), dividend(tdate,symbol,dividend). Submit (email) whatever commands/files you used to load the data into whatever database you're using, as well as the raw space usage of the tables in your database.
|
 |