Download presentation
Presentation is loading. Please wait.
Published byWalter Horton Modified over 8 years ago
1
DataBase - Check 01 DataBase 2 nd year Computer Science & Engineer 1
2
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
3
Sailors (sid, sname, rating, age) 22 Dustin 7 45.0 29 Brutus 1 33.0 31 Lubber 8 55.5 32 Andy 8 25.5 58 Rusty 10 35.0 64 Horatio 7 35.0 71 Zorba 10 16.0 74 Horatio 9 35.0 85 Art 3 25.5 95 Bob 3 63.5 DataBase - Check 013
4
Boats(bid, bname, color) 101 Interlake blue 102 Interlake red 103 Clipper green 104 Marine red DataBase - Check 014
5
Reserves (sid, bid, day) 22 101 10/10/98 22 102 10/10/98 22 103 10/8/98 22 104 10/7/98 31 102 11/10/98 31 103 11/6/98 31 104 11/12/98 64 101 9/5/98 64 102 9/8/98 74 103 9/8/98 DataBase - Check 015
6
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
7
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
8
Don’t solve correctly 1 and 2 you will FAIL! Database exam. DataBase - Check 018
9
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
10
Don’t solve correctly 3 Get through JOIN tutorial from SQL ZOO –again DataBase - Check 0110
11
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
12
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
13
6 Find the names of sailors who have reserved a red boat and a green boat. DataBase - Check 0113
14
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
15
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
16
Don’t solve 6 Correct! –you understand the limits of your knowledge you will learn latter how to solve this DataBase - Check 0116
17
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
18
Solve 6 correctly … using JOIN, UNION ++ please a standing ovation for … which are far beyond their time DataBase - Check 0118
19
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
20
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
21
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
22
Grade Add 1 for each correct solution Add 3 (from me) Here is your grade or FAIL! DataBase - Check 0122
23
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.