CSE 344 Midterm. Wednesday, February 19, 2014, 14:30-15:20. Question Points Score Total: 100

Similar documents
CSE 344 Midterm. Wednesday, February 19, 2014, 14:30-15:20. Question Points Score Total: 100

CSE 344 Midterm. Monday, Nov 4, 2013, 9:30-10:20. Question Points Score Total: 100

CSE 344 Midterm. November 9, 2011, 9:30am - 10:20am. Question Points Score Total: 100

CSE 344 Midterm. November 9, 2011, 9:30am - 10:20am. Question Points Score Total: 100

CSE 344 Midterm Exam

CSE 344 Midterm. Friday, February 8, 2013, 9:30-10:20. Question Points Score Total: 100

1 (10) 2 (8) 3 (12) 4 (14) 5 (6) Total (50)

CSE 344 Midterm. Monday, November 9th, 2015, 9:30-10:20. Question Points Score Total: 70

CSE 444, Winter 2011, Midterm Examination 9 February 2011

CSE 344 Final Examination

CSE 344 Final Exam. March 17, Question 1 / 10. Question 2 / 30. Question 3 / 18. Question 4 / 24. Question 5 / 21.

Score. 1 (10) 2 (10) 3 (8) 4 (13) 5 (9) Total (50)

CSE 344 Midterm. Monday, November 9th, 2015, 9:30-10:20. Question Points Score Total: 70

CSE 414 Midterm. Friday, April 29, 2016, 1:30-2:20. Question Points Score Total: 100

CSE 344 Final Examination

The SQL data-definition language (DDL) allows defining :

CSE 344 Final Examination

Chapter 3: Introduction to SQL. Chapter 3: Introduction to SQL

CSE414 Midterm Exam Spring 2018

SQL: Part II. Announcements (September 18) Incomplete information. CPS 116 Introduction to Database Systems. Homework #1 due today (11:59pm)

CSE 344 Final Examination

CSE 344 Midterm Exam

CSE 344 Midterm Exam Nov. 3, 2014 Sample Solution

McGill April 2009 Final Examination Database Systems COMP 421

CSE344 Midterm Exam Winter 2017

CS 327E Class 3. February 11, 2019

CSE 444 Final Exam. August 21, Question 1 / 15. Question 2 / 25. Question 3 / 25. Question 4 / 15. Question 5 / 20.

Today s topics. Null Values. Nulls and Views in SQL. Standard Boolean 2-valued logic 9/5/17. 2-valued logic does not work for nulls

Midterm Exam #2 (Version A) CS 122A Winter 2017

CSEP 514 Midterm. Tuesday, Feb. 7, 2017, 5-6:20pm. Question Points Score Total: 150

CSE344 Midterm Exam Fall 2016

Announcements (September 18) SQL: Part II. Solution 1. Incomplete information. Solution 3? Solution 2. Homework #1 due today (11:59pm)

CS145 Midterm Examination

Chapter 3: Introduction to SQL

Computer Science 597A Fall 2008 First Take-home Exam Out: 4:20PM Monday November 10, 2008 Due: 3:00PM SHARP Wednesday, November 12, 2008

Chapter 3: Introduction to SQL

Example Examination. Allocated Time: 100 minutes Maximum Points: 250

CS145 Midterm Examination

CSE 344 Final Examination

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

CSE 414 Midterm. April 28, Name: Question Points Score Total 101. Do not open the test until instructed to do so.

Where Are We? Next Few Lectures. Integrity Constraints Motivation. Constraints in E/R Diagrams. Keys in E/R Diagrams

CSE 444 Final Exam. December 17, Question 1 / 24. Question 2 / 20. Question 3 / 16. Question 4 / 16. Question 5 / 16.

CS2300: File Structures and Introduction to Database Systems

Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

QQ Group

Querying Data with Transact-SQL

Announcements (September 14) SQL: Part I SQL. Creating and dropping tables. Basic queries: SFW statement. Example: reading a table

CS40 Exam #2 November 13, 2002

SQL: Part III. Announcements. Constraints. CPS 216 Advanced Database Systems

Database Management Systems

CSE 344 Midterm. Wednesday, Oct. 31st, 2018, 1:30-2:20. Question Points Score Total: 100

Basic operators: selection, projection, cross product, union, difference,

CSEN 501 CSEN501 - Databases I

Name: Database Systems ( 資料庫系統 ) Midterm exam, November 15, 2006

CSE344 Final Exam Winter 2017

SQL Retrieving Data from Multiple Tables

Midterm Exam #1 Version B CS 122A Winter 2017

Lecture 3 More SQL. Instructor: Sudeepa Roy. CompSci 516: Database Systems

Midterm Exam #1 Version A CS 122A Winter 2017

CSE 414 Final Examination

Lecture 3 SQL - 2. Today s topic. Recap: Lecture 2. Basic SQL Query. Conceptual Evaluation Strategy 9/3/17. Instructor: Sudeepa Roy

Intermediate SQL ( )

Relational Model. Topics. Relational Model. Why Study the Relational Model? Linda Wu (CMPT )

IMPORTANT: Circle the last two letters of your class account:

CSE-6490B Final Exam

Course No: 4411 Database Management Systems Fall 2008 Midterm exam

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530

CIS 330: Applied Database Systems. ER to Relational Relational Algebra

Introduction to Data Management. Lecture #4 (E-R à Relational Design)

CSCB20 Week 4. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017

CSE 344 JANUARY 5 TH INTRO TO THE RELATIONAL DATABASE

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CS348: INTRODUCTION TO DATABASE MANAGEMENT (Winter, 2011) FINAL EXAMINATION

The Relational Model. Chapter 3

VIEW OTHER QUESTION PAPERS

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

CSE 344 Midterm. Wednesday, Nov. 1st, 2017, 1:30-2:20. Question Points Score Total: 100

Lecture 6 - More SQL

Computing for Medicine (C4M) Seminar 3: Databases. Michelle Craig Associate Professor, Teaching Stream

Birkbeck. (University of London) BSc/FD EXAMINATION. Department of Computer Science and Information Systems. Database Management (COIY028H6)

Midterm Exam #2 (Version B) CS 122A Spring 2018

The Relational Model. Chapter 3. Database Management Systems, R. Ramakrishnan and J. Gehrke 1

[12 marks] Consider the following schema for a program that pairs students with mentors who offer career advice.

Midterm 2: CS186, Spring 2015

CSE 444 Final Exam 2 nd Midterm

The Relational Model 2. Week 3

Introduction to SQL Part 1 By Michael Hahsler based on slides for CS145 Introduction to Databases (Stanford)

Midterm Review. Winter Lecture 13

Fall, 2004 CIS 550. Database and Information Systems Midterm Solutions

Comp 5311 Database Management Systems. 2. Relational Model and Algebra

EECS 647: Introduction to Database Systems

Lecture 3: SQL Part II

Chapter 2: Intro to Relational Model

CS 146 Database Systems

EECS 647: Introduction to Database Systems

Chapter 2: Intro to Relational Model

EXAMINATIONS 2013 MID-YEAR SWEN 432 ADVANCED DATABASE DESIGN AND IMPLEMENTATION

CSE 344 Midterm Nov 1st, 2017, 1:30-2:20

Transcription:

CSE 344 Midterm Wednesday, February 19, 2014, 14:30-15:20 Name: Question Points Score 1 30 2 50 3 12 4 8 Total: 100 This exam is open book and open notes but NO laptops or other portable devices. You have 50 minutes; budget time carefully. Please read all questions carefully before answering them. Some questions are easier, others harder. Plan to answer all questions, do not get stuck on one question. If you have no idea how to answer a question, write your thoughts about the question for partial credit. Good luck! 1

Reference for SQL Syntax Outer Joins -- left outer join with two selections: SELECT * FROM R LEFT OUTER JOIN S ON R.x = 55 AND R.y = S.z AND S.u = 99 The CREATE TABLE Statement: CREATE TABLE R ( attra VARCHAR(30) PRIMARY KEY, attrb int REFERENCES S(anotherAttr), attrc CHAR(20), attrd TEXT, -- PRIMARY KEY (attra), (equivalently) FOREIGN KEY (attrc, attrd) REFERENCES T(anAttrC, anattrd)) The CASE Statement: SELECT R.name, (CASE WHEN R.rating=1 THEN like it when R.rating=0 THEN do not like it when R.rating IS NULL THEN do not know ELSE unknown END) AS my_rating FROM R; The WITH Statement WITH T AS (SELECT * FROM R WHERE R.K > 10), S AS (SELECT * FROM R WHERE R.a > 50) SELECT * FROM T, S WHERE T.K<20 AND S.a < 20 Reference for the Relational Algebra 2

1 SQL 1. (30 points) There are many websites nowadays that offer Massive Open Online Courses (MOOC), where professors from top-class universities teach online courses. Students across the world have free online access to enroll in these courses and can learn different topics this way. The director of such an organization www.greatmooc.org, Dr. Alice VeryStrict, wanted to analyze the performance of the participating students and professors, and the quality of the offered courses to ensure that everything is going well. Since you are a student of CSE 344, can you help her write the following queries to do this data analysis? The information about students, instructors, and courses is stored in the following relations. Course(cid, name, year, duration) Student(sid, name, univ) Instructor(tid, name, univ) Enrollment(sid, cid) sid, cid reference Student and Course respectively Teaches(tid, cid) tid, cid reference Instructor and Course respectively. Assume that Duration is in month, so takes value between 1 to 12. Each course is entirely contained within the same year, i.e. does not span across two or more years. Feel free to abbreviate the relation names as C, S, I, E, T. The schema is shown on the top of the pages where you need it. Recall that variance of n numbers x 1,, x n is defined as 1 n n (x i µ) 2 = 1 n i=1 n x 2 i µ 2 i=1 where µ = 1 n n i=1 x i denotes the average of x 1,, x n. 3

Course(cid, name, year, duration), Student(sid, name, univ) Instructor(tid, name, univ), Enrollment(sid, cid), Teaches(tid, cid) (a) (9 points) First, Dr. VeryStrict wanted to examine the duration of courses offered by the professors from different universities in different years. So, write an SQL query to output the average duration (as avg duration), maximum duration (as max duration) and the variance of duration (as var duration) of the courses offered in the same year by professors from the same universities. Further, the answers should be sorted in decreasing order of the years (universities can be output in any order). e.g. The answer to the query should be of the form year univ avg duration max duration var duration 2013 MIT 2.8 5.2 0.001 2013 UW 3.5 4.4 0.09 2012 UW 1.9 2.7 0.02 The first answer tuple (2013, MIT, 2.8, 5.2, 0.001) has been computed using all courses offered in year = 2013 that were taught by some professor from MIT. 4

Course(cid, name, year, duration), Student(sid, name, univ) Instructor(tid, name, univ), Enrollment(sid, cid), Teaches(tid, cid) (b) (6 points) How would you modify the above answer if we change the requirements in the following three ways? DO NOT write the query once again. Just say which clause(s) you will add/modify and how. We want to output avg, max, and variance of durations of the courses for the year, univ pairs such that... i.... all courses offered in that year from that univ had duration 3 months. ii....some courses offered in that year from that univ had duration 3 months. iii.... the avg, max, and variance are computed (for each univ) over only those courses which had duration 3 months. 5

Course(cid, name, year, duration), Student(sid, name, univ) Instructor(tid, name, univ), Enrollment(sid, cid), Teaches(tid, cid) (c) (15 points) Dr. VeryStrict wanted to find the instructors who were unpopular in the year 2012, but gained popularity rapidly in the year 2013. Write an SQL query to output the name and univ of the instructors and the total number of (distinct) courses ever taught by him/her (as num courses) who has taught at most 50 distinct students (in all of his/her courses) in the year 2012 (so 0 students enrolled or no courses taught in 2012 should be included), but at least 300 distinct students in 2013. 6

2 Datalog, Relational Calculus, Relational Algebra 2. (50 points) In this problem you will continue to help Dr. VeryStrict to analyze the online courses in www.greatmooc.org. (You do not need to look at Problem 1 or your answers to Problem 1 for this problem). The information about students, instructors, and courses is stored in the following relations. Course(cid, name, year, duration) Student(sid, name, univ) Instructor(tid, name, univ) Enrollment(sid, cid) sid, cid reference Student and Course respectively Teaches(tid, cid) tid, cid reference Instructor and Course respectively. Assume that Duration is in month, so takes value between 1 to 12. Each course is entirely contained within the same year, i.e. does not span across two or more years. Feel free to abbreviate the relation names as C, S, I, E, T. The schema is shown on the top of the pages where you need it. (a) (30 points) We want to output the name of the students who in the year 2012 took only courses taught by professors from univ = UW, Note: your answer should include students who did not take any course in 2012. i. Write a Relational CALCULUS expression for this query. 7

Course(cid, name, year, duration), Student(sid, name, univ) Instructor(tid, name, univ), Enrollment(sid, cid), Teaches(tid, cid) ii. Write the query in SQL. 8

Course(cid, name, year, duration), Student(sid, name, univ) Instructor(tid, name, univ), Enrollment(sid, cid), Teaches(tid, cid) iii. Write a Relational ALGEBRA expression (or a logical query plan as a tree) for this query. 9

Course(cid, name, year, duration), Student(sid, name, univ) Instructor(tid, name, univ), Enrollment(sid, cid), Teaches(tid, cid) (b) (20 points) We want to output the name of the courses where all enrolled students are from the same university (but students in two different courses can be from two different universities). Note: your answer should include courses where no students were enrolled. i. Write a Relational CALCULUS expression for this query. ii. Write a non-recursive datalog + negation expression for this query. 10

3 XML, XPath, XQuery 3. (12 points) Consider the following XML document midterm.xml (the header has been omitted). <a m="1"> <b n="1" o="2"> <c p="3">3</c> <d/> </b> <b n="1" o="2"> <c p="3">3</c> <f s="1"/> <d q="3"> <e r="2">2</e> </d> </b> </a> (a) (6 points) Consider the following XPath expressions and write true/false for the following claims (if false, write the correct value, but no explanations are needed). Note: The count() method returns the number of nodes in a node-set. i. count(/*//*) = 9 ii. count(/*/*/@*) = 4 iii. count(/*/*/*) = 8 11

(b) (2 points) Does midterm.xml match with the following DTD? (write YES/NO). If your answer is NO, point to the line in the question where it does not match (just draw arrow(s) next to the line(s) in the DTD, and add a one-line explanation). <?xml version="1.0"?> <!DOCTYPE a [ <!ELEMENT a (b+)> <!ELEMENT b (c, d, f*)> <!ELEMENT c (#PCDATA)> <!ELEMENT d (e?)> <!ELEMENT f (#PCDATA)> ]> (c) (4 points) Suppose we want to write an XQuery to find all c elements with value 3. Do the following queries work? Write YES/NO. If your answer is NO, add a one-line explanation. i. let $t := doc("midterm.xml")/a/b/c where $t = 3 return $t ii. for $t in doc("midterm.xml")/a/b/c where $t = 3 return <c>{$t}</c> 12

4 E/R Diagram 4. (8 points) Write down the CREATE TABLE statements to create the Department and Product relations from the E/R diagram below. Note that you have to declare the primary keys (using PRIMARY KEY) and foreign keys (using REFERENCES, assume the same relation name as the entities) to get full credit. Assume all the attributes are of type VARCHAR(20). Department affiliation deptname address orgname pid isa University pname Organization year isa Company ceo Product makes (a) (4 points) Write CREATE TABLE statement for Department. 13

(b) (4 points) Write CREATE TABLE statement for Product. 14

For Rough Use 15

For Rough Use 16