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