1 Relational Algebra & SQL Query Formulation Exercise.

Slides:



Advertisements
Similar presentations
CS411 Database Systems Kazuhiro Minami 06: SQL. SQL = Structured Query Language Standard language for querying and manipulating data Has similar capabilities.
Advertisements

Union, Intersection, Difference (subquery) UNION (subquery) produces the union of the two relations. Similarly for INTERSECT, EXCEPT = intersection and.
1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra) Query Formulation Exercise.
Relational Algebra Chapter 4, Part A
Relational Algebra and SQL Exercises
SQL, RA, Sets, Bags Fundamental difference between theoretical RA and practical application of it in DBMSs and SQL RA  uses sets SQL  uses bags (multisets)
SQL Exercises – Part II April 11, 2017.
COP-5725 Practice Exercises
1 Introduction to SQL Select-From-Where Statements Multirelation Queries Subqueries.
SQL CSET 3300.
Relational Algebra and SQL Exercises Dr. Shiyong Lu Department of Computer Science Wayne State University ©copyright 2007, all rights.
Relational Algebra and SQL Exercises
1 Exercise 1  Given the following tables: employee (person_name, street, city)‏ works (person_name, company_name, salary)‏ company (company_name, city)‏
SQL and Relational Algebra Zaki Malik September 02, 2008.
SQL (2).
CS411 Database Systems Kazuhiro Minami 06: SQL. Join Expressions.
1 Database Systems Relations as Bags Grouping and Aggregation Database Modification.
1 Introduction to SQL Multirelation Queries Subqueries Slides are reused by the approval of Jeffrey Ullman’s.
Employee database: Conceptual Schema in ERD Chapter 3, page 62.
Structured Query Language – Continued Rose-Hulman Institute of Technology Curt Clifton.
Exercise Exercise3.1 8 Exercise3.1 9 Exercise
Exercise Exercise Exercise Exercise
Dr. Alexandra I. Cristea CS 319: Theory of Databases: C7.
Exercise Exercise Exercise Exercise
Exercise Exercise6.1 7 Exercise6.1 8 Exercise6.1 9.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #3.
CPSC-608 Database Systems Fall 2008 Instructor: Jianer Chen Office: HRBB 309B Phone: Notes #3.
Winter 2002Arthur Keller – CS 1807–1 Schedule Today: Jan. 24 (TH) u Subqueries, Grouping and Aggregation. u Read Sections Project Part 2 due.
Copyright © 2004 Pearson Education, Inc.. Chapter 8 SQL-99: Schema Definition, Basic Constraints, and Queries.
Cursors in Pl/SQL Database 1. Practice. Sample Database The schema of the sample database is the following: Drinkers (name, occupation, birthday, salary)
Chapter 6 Notes. 6.1 Simple Queries in SQL SQL is not usually used as a stand-alone language In practice there are hosting programs in a high-level language.
Onsdag The concepts in a relation data model SQL DDL DML.
Databases 1 Second lecture.
Section 3.2 Connections to Algebra.  In algebra, you learned a system of two linear equations in x and y can have exactly one solution, no solutions,
1 Introduction to SQL Database Systems. 2 Why SQL? SQL is a very-high-level language, in which the programmer is able to avoid specifying a lot of data-manipulation.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
1 Lecture 6 Introduction to SQL part 4 Slides from
Himanshu GuptaCSE 532-SQL-1 SQL. Himanshu GuptaCSE 532-SQL-2 Why SQL? SQL is a very-high-level language, in which the programmer is able to avoid specifying.
SCUHolliday - coen 1787–1 Schedule Today: u Subqueries, Grouping and Aggregation. u Read Sections Next u Modifications, Schemas, Views. u Read.
Access Test Solutions Fall 2014 Questions 7 and 8 Karl Lieberherr.
2( ) 8x + 14y = 4 -12x – 14y = x = x = 4 8x + 14y = 4 8(4) + 14y = y = y = -28 ___ ___ y = -2 The solution is (4, -2)
1 Introduction to Database Systems, CS420 SQL JOIN, Aggregate, Grouping, HAVING and DML Clauses.
1 Database Design: DBS CB, 2 nd Edition SQL: Select-From-Where Statements & Multi-relation Queries & Subqueries Ch. 6.
Select-From-Where Statements Multirelation Queries Subqueries
CPSC-310 Database Systems
CS 440 Database Management Systems
Relational Database Systems 1
Slides are reused by the approval of Jeffrey Ullman’s
Outerjoins, Grouping/Aggregation Insert/Delete/Update
Databases : More about SQL
Relational Algebra and SQL
CPSC-310 Database Systems
CS 480: Database Systems Lecture 9 February 4, 2013.
Example: R3 := R1 × R2 R3( A, R1.B, R2.B, C )‏ R1( A, B )‏ R2( B, C )‏ R3( A, R1.B, R2.B, C )‏
CS 480: Database Systems Lecture 15 February 18, 2013.
Schedule Today: Next After that Subqueries, Grouping and Aggregation.
CS 480: Database Systems Lecture 8 February 1, 2013.
CS 440 Database Management Systems
BACK SOLUTION:
CPSC-310 Database Systems
IST 210: Organization of Data
CPSC-310 Database Systems
IT 244 Database Management System
Relational Algebra and SQL Exercises
CPSC-608 Database Systems
More SQL Extended Relational Algebra Outerjoins, Grouping/Aggregation
CMSC-461 Database Management Systems
Instructor: Zhe He Department of Computer Science
Select-From-Where Statements Multirelation Queries Subqueries
Presentation transcript:

1 Relational Algebra & SQL Query Formulation Exercise

2 Exercise 4: Relational Algebra and SQL Given relational schema: Frequent (D, P) Serves (P, B) Likes (D, B) Attributes: P (pub), B (beer), D (drinker) 1) The pubs that serve a beer that Jefferson likes. 2) Drinkers that frequent at least one pub that serves “Bud” or “Becks”. 3) Drinkers that frequent only pubs that serve some beer they like 4) Drinkers that frequent only pubs that serve no beer they like.

3 1) Algebra  Solution 1:  Solution 2:  Solution 3:  Solution 4:

4 2) SQL  Solution 1 :  Solution 2: SELECT p FROM S, L WHERE S.b=L.b AND L.d=‘Jefferson’ SELECT d FROM F WHERE F.p in ( SELECT p FROM S WHERE b IN (‘Bud”, ‘Becks’))

5 2) SQL  Solution 3 : SELECT d FROM F EXCEPT SELECT d FROM ( SELECT * FROM F EXCEPT SELECT d,p FROM S, L WHERE S.b = L.b)

6 2) SQL  Solution 4 : SELECT d FROM F EXCEPT SELECT d FROM ( SELECT * FROM F INTERSECT SELECT d,p FROM S, L WHERE S.b = L.b)

7 2) SQL  Solution 4 (alternative solution) : SELECT d FROM F WHERE ( SELECT COUNT (DISTINCT p) FROM S, L WHERE F.p=S.p AND S.b=L.b AND L.d=F.d) = 0