+ -
当前位置:首页 → 问答吧 → 这到题还有没更精简的语句啊?

这到题还有没更精简的语句啊?

时间:2011-12-10

来源:互联网

网上的第51题
http://wenku.baidu.com/view/5897f82bcfc789eb172dc89c.html

我的做法:
select * from 成绩表 where 分数 between (select 分数下届 from 等级表 where 级别='a') and (select 分数上届 from 等级表 where 级别='a')

select * from 学生表 a join 成绩表 b on a.学号=b.学号 where b.分数>=(select 分数下届 from 等级表 where 级别='a') and b.分数<(select 分数上届 from 等级表 where 级别='a')

感觉语句太长了,请假高手有没更精简的语句!!!

作者: hy_number_one   发布时间: 2011-12-10

我觉得你写的挺好的。

作者: Beirut   发布时间: 2011-12-10

SQL code
select * from 成绩表, 等级表 where 分数 between 分数下届  and (select 分数上届  and  级别='a'

作者: Beirut   发布时间: 2011-12-10

看了执行计划貌似比你的好些。呵呵

总感觉ms把一些子查询给搞复杂了

作者: Beirut   发布时间: 2011-12-10

引用 2 楼 beirut 的回复:
SQL code
select * from 成绩表, 等级表 where 分数 between 分数下届 and (select 分数上届 and 级别='a'

膜拜

作者: fredrickhu   发布时间: 2011-12-10

SQL code
这样呢?
select
   *
from  
   成绩表a,等级表 b
where 
   a.分数>=b.分数下届 and a.分数<=b.分数下届 and b.级别='a'
and 
   a.学号=b.学号

作者: fredrickhu   发布时间: 2011-12-10

(select 分数上届 and 级别='a'

这个什么意识,怎么没from

作者: hy_number_one   发布时间: 2011-12-10

在继续问一个问题
好像子查询里面的别名,不能在外查询用?是不是啊?

作者: hy_number_one   发布时间: 2011-12-10

引用 2 楼 beirut 的回复:

SQL code
select * from 成绩表, 等级表 where 分数 between 分数下届 and (select 分数上届 and 级别='a'

语法写错了 

select * from 成绩表, 等级表 where 分数 between 分数下届 and 分数上届 and 级别='a'

作者: Beirut   发布时间: 2011-12-10

引用 7 楼 hy_number_one 的回复:

在继续问一个问题
好像子查询里面的别名,不能在外查询用?是不是啊?


嗯,必须的

一个括号把它给拒绝了

作者: Beirut   发布时间: 2011-12-10

在帮我看看53题可以不?谢谢了
这道题我实在写不出来了

作者: hy_number_one   发布时间: 2011-12-10