51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 1573|回复: 1
打印 上一主题 下一主题

[原创] 关于SQLZOO的几个问题

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2010-4-27 09:17:54 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
这是SQLZOO的里面的一些问题。。运行出来结果是正确的了。大家看看这些语句中有可以提高运行效率的吗= =~写SQL语句不久,写的不好,大家给些建议吧
movie(id, title, yr, score, votes, director)
actor(id, name)
casting(movieid, actorid, ord)

'John Travolta'哪一年最忙? 显示出他每年的出演电影数量.
select yr,b from (select actor.name,movie.yr,count(movie.id) b  from actor,movie,casting where movie.id=casting.movieid and actor.id=casting.actorid and actor.name='John Travolta' group by yr order by count(movie.id)desc)a
  
4b. 列出有'Julie Andrews'参演的所有电影名称以及该片的主角.
select movie.title,actor.name from  movie,actor, casting where movie.id=casting.movieid and actor.id=casting.actorid and title in (select movie.title from movie,actor, casting where movie.id=casting.movieid and actor.id=casting.actorid and  actor.name='Julie Andrews' ) and casting.ord=1

4c. 列出那些最起码在10部电影中出任过主角的演员
select actor.name from  movie,actor, casting where movie.id=casting.movieid and actor.id=casting.actorid and casting.ord=1 group by actor.name having count(movie.id)>=10) a

按演员人数的多少依次列出1978 的电影以及演员数.人数最多排在最前.
select movie.title,count(actor.name) from movie,actor, casting where movie.id=casting.movieid and actor.id=casting.actorid and yr=1978 group by movie.title order by count(actor.name)desc

4e. 列出所有和'Art Garfunkel'合作过的演员(不要列出'Art Garfunkel'他自己).
select actor.name from movie,actor, casting where movie.id=casting.movieid and actor.id=casting.actorid and movie.title in(
select movie.title from  movie,actor, casting where movie.id=casting.movieid and actor.id=casting.actorid and name='Art Garfunkel') and name not like 'Art Garfunkel'
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
 楼主| 发表于 2010-4-27 09:19:11 | 只看该作者
补充下。4C后面的最后的)a是不要的。发的时候多复制了点
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-9-24 19:25 , Processed in 0.077101 second(s), 28 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表