![]() ![]() |
||||||||
Lab Assignment 2 (due April 27, 16:00pm) |
||||||||||||||||||
General DescriptionIn this lab assignment, you will practise writing SQL queries to answer real world questions regarding the beer sales management DB. You will need to know SQL SELECT (including nested SELECT clause), natual join, DISTINCT keyword, ORDER BY (to order the query results), aggregation functions like AVG (to get average value for values of one column), MIN/MAX (to get mininum/maximum value for one column), COUNT (to count the number of values of one column). In some advanced questions, you need to know GROUP BY, HAVING clauses as well. Postgresql Searchable Online Manual and the Useful Links are the places you should visit when you have problems. The DB schema consists of five relations: Frequents, Bar, Serves, Likes and Drinker. (This part is the same as in lab 1, you may skip it if you want. I put here just for your quick reference.) //-- Frequents Relation -- //-- Bar Relation -- //-- Serves Relation -- //-- Likes Relation -- //-- Drinker Relation -- Assumptions about the schema: 1) The primary keys are underlined, note that in some cases they consists of several attributes. A primary key on table A should be defined as a foreign key on table B if it appears as an attribute in table B, e.g. drinker is a primary key on the Drinker table and a foreign key on the Likes table. 3) Assume each bar has only one owner and same owner may have multiple bars. 4) Salary is the yearly salary for the drinker. 5) Data type definition:
6) All data fields should be not null. AssignmentsThis assignment consists of 8 questions, for each question, you are asked to submit a script file that includes the SQL query and a log file that contains the session when you run your query. In order to simplify the evaluation process, we provide the standard DB schema and populate the tables with a set of standardized script files. Please drop the tables you have created in the first assignment and run these script files first. The following table shows the steps to run the script files. In case you need to remove the tuples from the five tables, use del_tables_content.script.
Query 1: Find drinker names and occupations of drinkers whose age is below 21. Query 2 : Find the name, occupation and salary of drinkers who like Bud Light: show your result in ascending order of salary, duplicate tuples are ok. Query 3 : Find bar names and address information for those bars that sell Bud Light at the cheapest price. Query 4 : Find bar names, address information, and bar owner for the bars that Tom frequents on Friday, e.g. day 5. Query 5 : Find the number of bars that Tom frequents, make sure you don't count the same bar multiple times. Query 6 : Find the minimum and maximum age of the drinkers who frequent the bar Watering Hole. Query 7 : Find the name and occupation for the youngest and oldest drinkers who frequents Watering Hole, no duplicates. Hint: use two SELECT queries and merge the query of subquery results with UNION. Query 8 : Find the age, occupation, and salary of drinkers who frequent bars more than 3 times a week. Submission Summary
You should use submit program to submit the assignments. If you dont know how to use submit, please read "how to use submit" for details. Sample submit commands for this lab assignment:
Useful Links
|
||||||||||||||||||
| SOE Webmail · SOE SSH · SOE Wiki · Search
· Sitemap · Contact us · Driving
directions
· Privacy · UCSC © Baskin School of Engineering, University of California, Santa Cruz 1156 High St., Santa Cruz, CA 95064 · (831) 459-2158 · webmaster@soe.ucsc.edu |