一、足球数据库
1.

select matchid,playerfrom goalwhere teamid = 'GER'
2.

SELECT id,stadium,team1,team2FROM gamewhere id = 1012
3.

SELECT player,teamid,stadium,mdateFROM game JOIN goal ON (id=matchid)where teamid = 'GER'
4.

select team1,team2,playerfrom game join goal on id=matchidwhere player like 'Mario%'
5.
SELECT player, teamid, coach,gtimeFROM goal as xJOIN eteam as yon x.teamid = y.idWHERE gtime<=10
6.

select mdate,teamnamefrom eteam as xjoin game as yon x.id = y.team1where coach = 'Fernando Santos'
7.

select playerfrom goal as xjoin game as yon x.matchid = y.idwhere stadium = 'National Stadium, Warsaw'
8.

题目要求:列出面对德国队有进球记录的球员姓名
思路拆解:
- 列出球员姓名:select name
- 面对德国队:
- 德国队的对手:teamid != ‘GER’
- 双方其中一队是德国队:team1 = ‘GER’ or team2 = ‘GER’
9.

SELECT teamname, count(*)FROM eteam JOIN goal ON id=teamidGROUP BY teamname
10.

11.
12.

SELECT matchid,mdate,count(*)FROM goal JOIN game ON id = matchidWHERE teamid = 'GER'GROUP BY matchid,mdate
13.
SELECT mdate,team1,sum(CASE WHEN teamid=team1 THEN 1 ELSE 0 END) as score1,team2,sum(CASE WHEN teamid=team2 THEN 1 ELSE 0 END) as score2FROM game JOIN goal ON matchid = idGROUP BY mdate,matchid,team1,team2
二、音乐数据库
三、more JOINT
6.

select namefrom actor as xjoin casting as y on x.id= y.actoridjoin movie as z on z.id = y.movieidwhere title = 'Casablanca'
7.

select namefrom actor as xjoin casting as y on x.id = y.actoridjoin movie as z on z.id = y.movieidwhere z.title = 'Alien'
8.

select titlefrom movie as xjoin casting as y on x.id = y.movieidjoin actor as z on z.id = y.actoridwhere name in ('Harrison Ford')
9.

select titlefrom movie as xjoin casting as y on x.id = y.movieidjoin actor as z on z.id = y.actoridwhere z.name = 'Harrison Ford' and y.ord != 1
10.

select title,namefrom movie as xjoin casting as y on x.id = y.movieidjoin actor as z on z.id = y.actoridwhere x.yr = 1962 and ord = 1
11.

SELECT yr,COUNT(title) FROMmovie JOIN casting ON movie.id=movieidJOIN actor ON actorid=actor.idWHERE name='Rock Hudson'GROUP BY yrHAVING COUNT(title) > 2
12.

SELECT title,nameFROM movie as xjoin casting as y on x.id = y.movieidjoin actor as z on z.id = y.actoridWHERE movieid IN (SELECT movieid FROM actorjoin casting on id=actoridWHERE name='Julie Andrews') and ord = 1
13.

select namefrom actor as xjoin casting as y on x.id = y.actoridjoin movie as z on z.id = y.movieidwhere ord = 1group by namehaving count(*) >= 15order by name
14.

select title,count(name)from movie as xjoin casting as y on x.id = y.movieidjoin actor as z on z.id = y.actoridwhere yr = 1978group by titleorder by count(name) desc,title
15.

select namefrom actor as xjoin casting as y on x.id = y.actoridwhere y.movieid in(select movieidfrom casting join actor on actorid = idwhere name = 'Art Garfunkel') and name != 'Art Garfunkel'
