DataBase - Check 01 DataBase 2 nd year Computer Science & Engineer 1.

Slides:



Advertisements
Similar presentations
1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra) Query Formulation Exercise.
Advertisements

1 Advanced SQL Queries. 2 Example Tables Used Reserves sidbidday /10/04 11/12/04 Sailors sidsnameratingage Dustin Lubber Rusty.
1 Database Systems ( 資料庫系統 ) October 22/24, 2007 Lecture #5.
Review Session ER and Relational –ER  Relational –Constraints, Weak Entities, Aggregation, ISA Relational Algebra  Relational Calculus –Selections/Projections/Joins/Division.
Introduction to Database Systems 1 SQL: The Query Language Relation Model : Topic 4.
1 SQL: Structured Query Language (‘Sequel’) Chapter 5.
CS 166: Database Management Systems
1 Relational Calculus Chapter 4 – Part II. 2 Formal Relational Query Languages  Two mathematical Query Languages form the basis for “real” languages.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Constraints, Triggers Chapter 5.
SQL.
SQL: The Query Language Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein and etc for some slides.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Programming, Triggers Chapter 5.
CS 405G: Introduction to Database Systems
SQL (2).
CMPT 258 Database Systems SQL: Queries, Constraints, Triggers (Chapter 5) Part II home.manhattan.edu/~tina.tian.
SQL Review.
1 SQL: Structured Query Language (‘Sequel’) Chapter 5.
SQL 2 – The Sequel R&G, Chapter 5 Lecture 10. Administrivia Homework 2 assignment now available –Due a week from Sunday Midterm exam will be evening of.
1 SQL (Simple Query Language). 2 Query Components A query can contain the following clauses –select –from –where –group by –having –order by Only select.
FALL 2004CENG 351 File Structures and Data Management1 SQL: Structured Query Language Chapter 5.
Relational Calculus CS 186, Spring 2007, Lecture 6 R&G, Chapter 4 Mary Roth   We will occasionally use this arrow notation unless there is danger of.
1 Rewriting Minus Queries Using Not In SELECT S.sname FROM Sailors S, Boats B, Reserves R WHERE S.sid = R.sid and R.bid = B.bid and B.color = ‘red’ MINUS.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Constraints, Triggers Chapter 5.
SELECT S.rating, MIN (S.age) AS minage FROM Sailors S WHERE S.age >= 18 GROUP BY S.rating HAVING COUNT (*) > 1 sidsnameratingage 22dustin745 29brutus133.
1 The Oracle Database System Querying the Data Database Course The Hebrew University of Jerusalem.
1 SQL: Structured Query Language Chapter 5. 2 SQL and Relational Calculus relationalcalculusAlthough relational algebra is useful in the analysis of query.
1 Rewriting Intersect Queries Using In SELECT S.sid FROM Sailors S, Boats B, Reserves R WHERE S.sid = R.sid and R.bid = B.bid and B.color = ‘red’ INTERSECT.
Relational Calculus R&G, Chapter 4   We will occasionally use this arrow notation unless there is danger of no confusion. Ronald Graham Elements of Ramsey.
1 Advanced SQL. 2 Consider the following relations: –pupil (pupil_name, address, class, birthyear) –subject (subject_name, class, teacher) –grades (pupil_name,
Exercises Find the names of sailors who’ve reserved boat #103 { N |  S  Sailors (S.name = N.name   R  Reserves(S.sid = R.sid  R.bid = 103)) }
CSC343 – Introduction to Databases - A. Vaisman1 SQL: Queries, Programming, Triggers.
Chapter 5.  Data Manipulation Language (DML): subset of SQL which allows users to create queries and to insert, delete and modify rows.  Data Definition.
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
LeongHW, SoC, NUS (UIT2201: Database) Page 1 © Leong Hon Wai, Animation of SQL Queries To illustrate three SQL queries: –Q1: simple select (one.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L6_SQL(1) 1 SQL: Queries, Constraints, Triggers Chapter 5 – Part 1.
SQL Part I: Standard Queries. COMP-421: Database Systems - SQL Queries I 2 Example Instances sid sname rating age 22 debby debby lilly.
SQL Examples CS3754 Class Note 11 CS3754 Class Note 11, John Shieh,
SQL 2 Introduction Structured Query Language (SQL): the most widely used commercial relational database language Originally.
SQL: Queries, Programming, Triggers. Example Instances We will use these instances of the Sailors and Reserves relations in our examples. If the key for.
ICS 321 Fall 2009 SQL: Queries, Constraints, Triggers Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 9/8/20091Lipyeow.
1 Database Systems ( 資料庫系統 ) October 24, 2005 Lecture #5.
Introduction to SQL ; Christoph F. Eick & R. Ramakrishnan and J. Gehrke 1 Using SQL as a Query Language COSC 6340.
CMPT 258 Database Systems SQL Queries (Chapter 5).
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 5 SQL.
1 SQL: The Query Language (Part II). 2 Expressions and Strings v Illustrates use of arithmetic expressions and string pattern matching: Find triples (of.
1 SQL: Structured Query Language (‘Sequel’) Chapter 5.
Relational Calculus Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.
SQL: The Query Language Part 1 R &G - Chapter 5 The important thing is not to stop questioning. Albert Einstein.
1 SQL: The Query Language. 2 Example Instances R1 S1 S2 v We will use these instances of the Sailors and Reserves relations in our examples. v If the.
SQL: The Query Language Part 1 R&G - Chapter 5 1.
1 CS122A: Introduction to Data Management Lecture #7 Relational Algebra I Instructor: Chen Li.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Basic SQL Queries.
1 CS122A: Introduction to Data Management Lecture 9 SQL II: Nested Queries, Aggregation, Grouping Instructor: Chen Li.
Relational Calculus Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 4.
Basic SQL Queries Go over example queries, like 10 > ALL.
COP Introduction to Database Structures
© פרופ' יהושע שגיב, האוניברסיטה העברית
01/31/11 SQL Examples Edited by John Shieh CS3754 Classnote #10.
SQL The Query Language R & G - Chapter 5
Database Systems October 14, 2009 Lecture #5.
Database Systems (資料庫系統)
Basic SQL Lecture 6 Fall
Database Applications (15-415) SQL-Part II Lecture 9, February 04, 2018 Mohammad Hammoud.
CS 405G: Introduction to Database Systems
Relational Calculus.
SQL: The Query Language Part 1
קורס קבצים ובסיסי נתונים
? Data Science 100 Databases Part 2 (The SQL) Slides by:
SQL: Structured Query Language
Relational Calculus Chapter 4 – Part II.
Presentation transcript:

DataBase - Check 01 DataBase 2 nd year Computer Science & Engineer 1

Schema Sailors –(sid: integer, sname: string, rating: integer, age: real) Boats –(bid: integer, bname: string, color: string) Reserves –(sid: integer, bid: integer, day: date) DataBase - Check 012

Sailors (sid, sname, rating, age) 22 Dustin Brutus Lubber Andy Rusty Horatio Zorba Horatio Art Bob DataBase - Check 013

Boats(bid, bname, color) 101 Interlake blue 102 Interlake red 103 Clipper green 104 Marine red DataBase - Check 014

Reserves (sid, bid, day) /10/ /10/ /8/ /7/ /10/ /6/ /12/ /5/ /8/ /8/98 DataBase - Check 015

1 Find the' names and ages of all sailors. SELECT DISTINCT S.sname, S.age FROM Sailors S SELECT sname, age FROM Sailors DataBase - Check 016

2 Find all sailors with a rating above 4. SELECT S.sid, S.sname, S.rating, S.age FROM Sailors S WHERE S.rating > 4 SELECT * FROM Sailors –WHERE rating > 7 DataBase - Check 017

Don’t solve correctly 1 and 2 you will FAIL! Database exam. DataBase - Check 018

3 Find the names of sailors who have reserved boat number 103. SELECT S.sname FROM Sailors S, Reserves R WHERE S.sid = R.sid AND R.bid=103 SELECT S.sname FROM Sailors S, JOIN Reserves R ON S.sid = R.sid –WHERE R.bid=103 DataBase - Check 019

Don’t solve correctly 3 Get through JOIN tutorial from SQL ZOO –again DataBase - Check 0110

4 Find the names of sailors who have reserved a red boat. SELECT S.name FROM Sailors S, Reserves R, Boats B WHERE S.sid = R.sid AND R.bid = B.bid –AND B.color = 'red' SELECT S.name FROM Sailors S –JOIN Reserves R ON S.sid = R.sid –JOIN Boats B ON R.bid = B.bid –WHERE B.color = 'red' DataBase - Check 0111

5 Find the names of sailors who have reserved a red boat or a green boat. SELECT S.name FROM Sailors S –JOIN Reserves R ON S.sid = R.sid –JOIN Boats B ON R.bid = B.bid –WHERE B.color = 'red' OR B.color = 'green' DataBase - Check 0112

6 Find the names of sailors who have reserved a red boat and a green boat. DataBase - Check 0113

Solve 6 like … SELECT S.name FROM Sailors S –JOIN Reserves R ON S.sid = R.sid –JOIN Boats B ON R.bid = B.bid –WHERE B.color = 'red' AND B.color = 'green' Don’t understand anything! – the color of a single Boats row could not be red and green in the same time DataBase - Check 0114

Gotcha In programming, a gotcha is a feature of a system, a program or a programming language that works in the way it is documented but is counter-intuitive and almost invites mistakes because it is both enticingly easy to invoke and completely unexpected and/or unreasonable in its outcome. DataBase - Check 0115

Don’t solve 6 Correct! –you understand the limits of your knowledge you will learn latter how to solve this DataBase - Check 0116

SELECT S.sname FROM Sailors S, Reserves R1, Boats B1, Reserves R2, Boats B2 WHERE S.sid = R1.sid AND R1.bid = B1.bid AND S.sid = R2.sid AND R2.bid = B2.bid AND B1.color='red' AND B2.color = 'green' SELECT S.sname FROM Sailors S, Reserves R1, Boats B1 WHERE S.sid = R1.sid AND R1.bid = B1.bid AND B1.color = 'red' UNION SELECT S.sname FROM Sailors S, Reserves R2, Boats B2 WHERE S.sid = R2.sid AND R2.bid = B2.bid AND B2.color = 'green' DataBase - Check 0117

Solve 6 correctly … using JOIN, UNION ++ please a standing ovation for … which are far beyond their time DataBase - Check 0118

7 Find the name and rating of the sailor with the highest rating. SELECT S.sname, S.rating FROM Sailors S WHERE S.rating >= ALL ( SELECT rating FROM Sailors) DataBase - Check 0119

Don’t solve correctly 7 FAIL! - you don’t pay enough attention to DataBase laboratory and course hours … similar with query already discussed at laboratory hours – but simpler –largest (Area) country from each region DataBase - Check 0120

Solve 7 like … SELECT S.sname, MAX(rating) FROM Sailors S You learn something from sqlzoo, but you understand wrong – wishful thinking AGGREGATE operators –will be discussed latter … DataBase - Check 0121

Grade Add 1 for each correct solution Add 3 (from me) Here is your grade or FAIL! DataBase - Check 0122

if you say like Tweety "I thought I thought I know SQL“ don’t forget there is a Sylvester DataBase exam. looming in 2011 DataBase - Check 0123