3.顯示每一個德國入球的球員名,隊伍名,場館和日期。 SELECT player,teamid,stadium,mdate FROM goal JOIN game ON (goal.matchid=game.id) where teamid = 'GER'
1 2 3
4.列出球員名字叫Mario (player LIKE'Mario%')有入球的 隊伍1 team1, 隊伍2 team2 和 球員名 player select team1,team2,player from game join goal on (game.id=goal.matchid) where player like'Mario%'
6.列出'Fernando Santos'作為隊伍1 team1 的教練的賽事日期,和隊伍名。 select mdate,teamname from game join eteam on (game.team1=eteam.id) where coach = 'Fernando Santos'
1 2 3
7.列出場館 'National Stadium, Warsaw'的入球球員。 select player from game join goal on (game.id=goal.matchid) where stadium = 'National Stadium, Warsaw'
More Difficult
1 2 3
8.只列出全部賽事,射入德國龍門的球員名字。 selectdistinct player from game join goal on matchid = id where (team1='GER'or team2='GER') and teamid!='GER'
1 2 3 4
9.列出隊伍名稱 teamname 和該隊入球總數 select teamname, count(player) from eteam JOIN goal ON id=teamid group by teamname
1 2 3 4
10.列出場館名和在該場館的入球數字。 select stadium, count(player) from game JOIN goal ON id=matchid group by stadium
1 2 3 4 5
11.每一場波蘭'POL'有參與的賽事中,列出賽事編號 matchid, 日期date 和入球數字。 select matchid,mdate,count(player) from game join goal on id = matchid where team1 = 'POL'or team2 = 'POL' group by matchid,mdate
1 2 3 4 5
12.每一場德國'GER'有參與的賽事中,列出賽事編號 matchid, 日期date 和德國的入球數字。 select matchid,mdate,count(player) from game join goal on id = matchid where (team1 = 'GER'or team2 = 'GER') and teamid = 'GER' group by matchid,mdate
1 2 3 4 5 6 7 8 9 10 11
13.List every match with the goals scored byeach team as shown. This will use"CASE WHEN" which has not been explained inany previous exercises. Noticein the query given every goal is listed. If it was a team1 goal then a 1 appears in score1, otherwise there is a 0. You could SUM this columntoget a countof the goals scored by team1. Sort your resultby mdate, matchid, team1 and team2.
1.找出收錄歌曲song 'Alison' 碟名title和歌手artist SELECTtitle,artist FROM album JOIN track ON (album.asin=track.album) WHERE song = 'Alison'
1 2 3
2.哪一歌手artist 錄了歌曲 song 'Exodus'? select artist from album join track on (asin=album) where song = 'Exodus'
1 2 3
3.為大碟album 'Blur', 顯示每一首歌的歌名 song 。 select song from album join track on (asin=album) where title = 'Blur'
1 2 3
4.為每一大碟album顯示歌名title和每大碟的歌曲track數量。 SELECT title,count(song) FROM album JOIN track ON (asin=album) GROUP BY title
1 2 3 4
5.為每一大碟album列出碟名title 歌名中有'Heart'一詞的歌曲數量。 (沒有這些歌的大碟不用列出). select title,count(song) from album join track on (asin=album) where song like '%Heart%' group by title
1 2 3
6.主題歌曲是歌名 song 和大碟名字 title相同。找出主題歌曲。 select song from album join track on (asin=album) where song = title
1 2 3
7.同名大碟是指大碟和歌手名字相同。 (例如大碟'Blur' 是由樂隊 'Blur'主唱)。 找出同名大碟。 selecttitlefrom album where artist = title
1 2 3 4
8.找出歌曲收錄在2隻以上的大碟中。列出收錄次數。 select song,count(distinct album) from track group by song having count(distinct album) > 2
1 2 3 4
9.好價大碟是指大碟中每一首歌曲的價格是少於5角。 找出好價大碟,列出大碟名字,售價和歌曲數量。 select title,price,count(song) from track join album a on (a.asin=album) where 0.5 > (select price/count(song) from track join album b on (b.asin=album) where a.asin = b.asin group by price) group by title,price
1 2 3 4 5
10.歌手Wagner的大碟 Ring cycle 有173首歌曲, 歌手Bing Crosby有一大碟 收錄了 101首歌曲。 按歌曲量(多至少)列出每一大碟的碟名和歌曲數量。 select title,count(song) from album join track on (asin=album) group by title order by count(song) desc
Quiz
1.You want to find the stadium where player ‘Dimitris Salpingidis’ scored. Select the JOIN condition to use: Answer:
1
game JOIN goal ON (id=matchid)
2.You JOIN the tables goal and eteam in an SQL statement. Indicate the list of column names that may be used in the SELECT line: Answer:
3.Select the code which shows players, their team and the amount of goals they scored against Greece(GRE). Answer:
1 2 3 4 5
SELECT player, teamid, COUNT(*) FROM game JOIN goal ON matchid = id WHERE (team1 = "GRE"OR team2 = "GRE") AND teamid != 'GRE' GROUP BY player, teamid
4.Select the result that would be obtained from this code:
1 2 3
SELECTDISTINCT teamid, mdate FROM goal JOIN game on (matchid=id) WHERE mdate = '9 June 2012'
Answer:
5.Select the code which would show the player and their team for those who have scored against Poland(POL) in National Stadium, Warsaw. Answer:
1 2 3 4 5
SELECTDISTINCT player, teamid FROM game JOIN goal ON matchid = id WHERE stadium = 'National Stadium, Warsaw' AND (team1 = 'POL'OR team2 = 'POL') AND teamid != 'POL'
6.Select the code which shows the player, their team and the time they scored, for players who have played in Stadion Miejski (Wroclaw) but not against Italy(ITA). Answer:
1 2 3 4
SELECTDISTINCT player, teamid, gtime FROM game JOIN goal ON matchid = id WHERE stadium = 'Stadion Miejski (Wroclaw)' AND (( teamid = team2 AND team1 != 'ITA') OR ( teamid = team1 AND team2 != 'ITA'))
7.Select the result that would be obtained from this code:
1 2 3 4
SELECT teamname, COUNT(*) FROM eteam JOIN goal ON teamid = id GROUP BY teamname HAVING COUNT(*) < 3