CSIT5300: Advanced Database Systems

Similar documents
Database Management Systems. Chapter 5

{ } Plan#for#Today# CS#133:#Databases# RelaKonal#Calculus# Rel.#Alg.#Compound#Operator:# Division# A B = x y B( x, y A)

CSIT5300: Advanced Database Systems

RESERVATION.Sid and RESERVATION.Bid are foreign keys referring to SAILOR.Sid and BOAT.Bid, respectively.

Comp115: Databases. Relational Algebra

SQL Aggregate Queries

RESERVATION.Sid and RESERVATION.Bid are foreign keys referring to SAILOR.Sid and BOAT.Bid, respectively.

CS 461: Database Systems. Relational Algebra. supplementary material: Database Management Systems Sec. 4.1, 4.2 class notes

sname rating 8 .forward Relational Algebra Operator Precedence Sample Query 0 Example Schema bid 103 sname( ( Sailors) Relational Algebra Queries

Homework 2: Relational Algebra and SQL Due at 5pm on Wednesday, July 20, 2016 NO LATE SUBMISSIONS WILL BE ACCEPTED

Solution: Homework 2: Relational Algebra Due at 5pm on Monday, February 5, 2018

CS 500: Fundamentals of Databases. Midterm review. Julia Stoyanovich

PART 3 MODULE 6 GEOMETRY: UNITS OF GEOMETRIC MEASURE

Upgrading Bio-Plex Manager 4.1, 5.0, or 6.0 Software to Bio-Plex Manager 6.1 Software

First Name: Last Name: Student scores will be sent to the address you provide above.

Regional Seminar on Costs and Tariffs for Member Countries of the Regional Group for Asia and Oceania (SG3RG-AO)

FROM REEL TO DEAL PDF

1 st Guam Dragon Boat Invitational U23 Festival Matapang Beach Park, Tumon, Guam July 29-30, 2017

GEG Dragon Boat Teams Had Great Achievements in the Macau Small Dragon Boat Mid-Autumn Festival Cup

University of Groningen & The Conference Board Asia s Productivity Performance and Potential: A Sectoral Perspective

Choose the expression(s) that is (are) equivalent to the given rational number. 20 A. B. C..5 A..67 B..6 C. 30 D. E. 1 4 D. 4 E.

SQL language: set operators

Statistical Appendix. Tim Beal. Table A1: China s share of world merchandise trade,

GUANGZHOU PRACTICAL MEDIA GUIDE 1-5 February 2018

Database Systems CSE 414

中國香港品勢總會 THE POOMSAE UNION OF HONG KONG, CHINA website:

VOLVO OCEAN RACE - The Route

Homework 4 PLAYERS, TEAMS, MATCHES, PENALTIES, COMMITTEE_MEMBERS

VOLVO OCEAN RACE - The Route

Biomechanical Analysis of Taekwondo Kicking Technique, Performance & Training Effects

Trigonometric Functions

NOTICE OF RACE. LBC Asian Open Regatta Lantau Boat Club October Discovery Bay, Hong Kong

Expanding Square Search Pattern HEY! I M OVER HERE!!!

2019 World Rowing Coastal Championships

COMP 406 Lecture 05. Artificial. Fiona Yan Liu Department of Computing The Hong Kong Polytechnic University

HONG KONG JUNIOR CLASSIC AT CLEARWATER BAY PRESENTED BY SELINA LI FEBRUARY 20-22, 2019 THE CLEARWATER BAY GOLF AND COUNTRY CLUB HONG KONG SAR

Invitation of Nanning International Board and Card Games

Cost and Benefit Analysis of Possible Philippine Participation in the Trans-Pacific Partnership Agreement

Using Big Data to Model Football. Edward Griffiths Hong Kong Jockey Club 29 April 2015

Great Britain senior rowing squad. 5 th place at Senior European Championships. 5 th place at World U23 Rowing Championships.

The Great Kayak Expedition

FIL Qualifying Event Proposal. Problem Statement. Proposal for voting at GA

VOLVO OCEAN RACE - The Route

Lecture 18 10/09/15. CMPSC431W: Database Management Systems. Instructor: Yu- San Lin

Gears Ratios and Speed / Problem Solving

REPORT TO THE GAISF GENERAL ASSEMBLY

HONG KONG CANOE UNION

The Kowloon Cup comprises an Island Race on the Saturday and a Pursuit Race on the Sunday, with a finish for prize-giving and seafood meal at Leung

Hebe Haven Yacht Club Yacht Racing Sponsorship Opportunities 2018

Math Spring Operational Geometry PBA Item #18 Classmates in the Pool VH003506

Reliable Speed Prediction: Propulsion Analysis and a Calculation Example

averun.com Installation Guide

Couples, Relations and Functions

MEMO. Andy Taylor, CAO and ELT Stephen Chait, Director, Economic Growth, Culture and Entrepreneurship Department

British Universities and Colleges Sport. British Universities Sailing Association. British University Fleet Racing Championships 2017

1.2. Barite Market Overview

Press Release. Date 17 July 2018 Total Pages 5

Using SQL in MS Access

Relational Schema Design. Part II: Schema Decomposition. Example of Bad Design. Result of bad design: Anomalies

LEVEL 2 FUNCTIONAL SKILLS MATHEMATICS 09866

CANSAIL DINGHY SAILOR PROGRAM GUIDE CANADA. CANSAIL Dinghy Sailor Program Guide 1 of 6 January 2019


Engaging staff in cultivating a happy and caring culture through Sports Association in Hong Kong West Cluster

2018 Asian Rowing Coastal Championships

Institutional Arrangements and International Trade: Evidence from Hong Kong* Volker Nitsch Free University Berlin

NACRA UNDER 19 TOURNAMENT

HKSF Selection Trials HKODA NATIONAL & OPEN CHAMPIONSHIPS st 4 th October 2015

Tropical Cyclone Climate in the Asia- Pacific Region and the Indian Oceans

FEBRUARY 2018 AUCTION REPORT

Section 8: Model-View-Controller

Adult Summer Reading 2018

Overview of trade and export trends in the boating industry worldwide.

DG AGRI DASHBOARD: CITRUS FRUIT Last update:

DG AGRI DASHBOARD: CITRUS FRUIT Last update:

SESSION 10. UNSD COLLECTION OF VITAL STATISTICS

Remote Training-Support of Running Form for Runners with Wireless Sensor

Global Maritime Clusters Competitive Advantages & Business Development Opportunities (Malta)

CURRENT DEMOGRAPHIC SITUATION IN LATVIA

Date: 24 May 2016 Total pages: 5 THE HONG KONG DRAGON BOAT CARNIVAL RELOCATES TO CENTRAL WITH THE BIGGEST BASH YET

Eg.1: If all the words are of different groups, then they will be shown by the diagram as given below. Dog, Cow, Horse

THE PLAYING PATTERN OF WORLD S TOP SINGLE BADMINTON PLAYERS

Historical precipitation data rescue to investigate the long-term variability of the Asian monsoon

Addition and Subtraction of Rational Expressions

International Hobie 16 Class Association

Operations on Radical Expressions; Rationalization of Denominators

SINGAPORE s OLDEST DRAGON BOAT RACE! Bulletin 2 September SINGAPORE DRAGON BOAT ASSOCIATION Your professional Dragon Boat Partner

Yvonne Sadovy University of Hong Kong

Number Bases LESSON ONE By John Owen. Computer Science

Measuring Relative Achievements: Percentile rank and Percentile point

SOCOMEC UPS Participates 2008 Summer Olympic Games

Trigonometry Problems

Marathon 101 Cheer for the Runners Campaign Cheering Team Competition Students Spare no Efforts to Cheer for Marathon Runners

SIGNATURE EVENT PREVIEW 2019

Sail Around The World 2013 Calendar By Sail Magazine

SQL LiteSpeed 3.0 Installation Guide

ECE 697B (667) Spring 2003

[Directives] 1. Aim: to enhance skill level of gymnastics and identify potential gymnasts in Hong Kong

International Sailing Federation (ISAF) Paralympic Development Program

Global Information Assurance Certification Paper. Copyright SANS Institute Author Retains Full Rights

CODE OF CONDUCT FOR THE KARATEDO FEDERATION OF HONG KONG, CHINA LIMITED

Transcription:

CSIT5300: Advanced Database Systems E03: SQL Part 1 Exercises Dr. Kenneth LEUNG Department of Computer Science and Engineering The Hong Kong University of Science and Technology Hong Kong SAR, China kwtleung@cse.ust.hk CSIT5300

Exercise #1 Let R(A,B,C) and S(D,E,F) be two union compatible relation schemas. Convert the following algebra expressions to SQL (for simplicity, you can omit distinct): π A (R) A R σ C=12 (R) * R C=12 π A,F (R JOIN C=D S) A, F R, S C=D π A (R) - π D (S) A R except D S kwtleung@cse.ust.hk CSIT5300 2

Exercise #2 (Example Database Schema and Instance) Sailors (sid, sname, rating, age), Sailors sid sname rating age 22 dustin 7 45.0 31 lubber 8 55.5 58 rusty 10 35.0 Reserves sid bid day 22 101 10/10/96 58 103 11/12/96 kwtleung@cse.ust.hk CSIT5300 3

Exercise #2 Q1 Q1: Find the names of sailors who reserved bid=103 S.sid S x R S.sname Sailors as S, Reserves as R S.sid=R.sid and R.bid=103 R.sid (sid) sname rating age (sid) bid day 22 dustin 7 45.0 22 101 10/10/96 22 dustin 7 45.0 58 103 11/12/96 31 lubber 8 55.5 22 101 10/10/96 31 lubber 8 55.5 58 103 11/12/96 58 rusty 10 35.0 22 101 10/10/96 58 rusty 10 35.0 58 103 11/12/96 kwtleung@cse.ust.hk CSIT5300 4

Exercise #2 Q2 Q2: Find the sid s of sailors who reserved a red or a green boat Solution #1 Solution #2 R.sid Boats as B, Reserves as R R.bid=B.bid and (B.color= red or B.color= green ) What do we get if we replace or by and in the first solution? union R.sid Boats as B, Reserves as R R.bid=B.bid and B.color= red R.sid Boats as B, Reserves as R R.bid=B.bid and B.color= green What do we get if we replace union by except in the second solution? kwtleung@cse.ust.hk CSIT5300 5

Exercise #2 Q3 Q3: Find the sid s of sailors who reserved a red and a green boat Solution #1 S.sid Sailors as S, Boats as B1, Reserves as R1, Boats as B2, Reserves as R2 S.sid=R1.sid and R1.bid=B1.bid and B1.color= red and S.sid=R2.sid and R2.bid=B2.bid and B2.color= green Solution #2 intersect Key field! S.sid Sailors as S, Boats as B, Reserves as R S.sid=R.sid and R.bid=B.bid and B.color= red S.sid Sailors as S, Boats as B, Reserves as R S.sid=R.sid and R.bid=B.bid and B.color= green What if instead of the sid we want the sname? Would the queries be correct if we replace S.sid with S.sname in? kwtleung@cse.ust.hk CSIT5300 6

Exercise #2 Q4 Q4: Find the names of sailors who have not reserved bid=103 S.sname Sailors as S S.sid not in ( R.sid Reserves as R R.bid=103) kwtleung@cse.ust.hk CSIT5300 7

Exercise #2 Q5 Q5: Find the names of sailors who have reserved a red boat (you must use in) S.sname Sailors as S S.sid in ( R.sid Reserves as R R.bid in ( B.bid Boats as B B.color=red) What if we replace the first in with not in? What if we replace the second in with not in? What if we replace both in with not in? kwtleung@cse.ust.hk CSIT5300 8

Exercise #2 Q6 Q6: Find the names of sailors who have reserved bid=103 (you must use exists) S.sname Sailors as S exists ( * Reserves as R R.bid=103 and S.sid=R.sid) What if we replace exists with not exists? What if we replace exists with unique? kwtleung@cse.ust.hk CSIT5300 9

Exercise #2 Q7 Q7: Find the record of the sailor with the highest rating * Sailors as S S.rating >= all ( S2.rating Sailors as S2) What if we replace all with some? kwtleung@cse.ust.hk CSIT5300 10

Exercise #2 Q8 Q8: Find the names of sailors who reserved all boats S.sname Sailors as S not exists (( B.bid Boats as B) except ( R.bid Reserves as R R.sid=S.sid)) kwtleung@cse.ust.hk CSIT5300 11