【Tips】
- sqlzoo官网链接:
- 每个系列开头介绍所用表及其信息
- 每道题含有题目描述、代码和结果,本系列第10题测试未通过
- 题目为自己简写,最好在官网查看具体题目
- 部分测试结果不完整,仅为一部分截图
合并表格之音乐数据库练习链接:
- 大碟(asin,碟名,歌手,售价,发行,标签,排名)
- 曲目(大碟,碟号,轨号,歌名)
SELECT title,artist FROM album JOIN track ON (album.asin=track.album) WHERE song = ‘Alison‘
SELECT artist FROM album JOIN track ON album.asin=track.album WHERE song=‘Exodus‘
SELECT song FROM album JOIN track ON album.asin=track.album WHERE title=‘Blur‘
SELECT title,COUNT(song) FROM album JOIN track ON (asin=album) GROUP BY title
SELECT title,COUNT(song) FROM album JOIN track ON album.asin=track.album WHERE song LIKE ‘%Heart%‘ GROUP BY title
SELECT song FROM album JOIN track ON album.asin=track.album WHERE song=title
SELECT title FROM album WHERE title=artist
SELECT song,COUNT(DISTINCT title) FROM track JOIN album ON album=asin GROUP BY song HAVING COUNT(DISTINCT title)>2
SELECT title,price,COUNT(song) FROM album JOIN track ON asin=album GROUP BY title,price HAVING price/COUNT(song) < 0.5
SELECT title,COUNT(song) FROM album JOIN track ON asin=album GROUP BY title ORDER BY COUNT(song) DESC