4个回答
展开全部
我们先分析一下,假设有一个表叫grade,里面有一列叫A,A中记录的是很多学生的成绩,那么我们可以采取这种办法求出第三名学生的成绩(嵌套三次查询语句):
select min(A) AS A3 from grade where A>(select min(A) AS A2 from grade where A>(SELECT Min(A) AS A1 FROM grade))
同样,将这个句嵌套五次就可以取出第五名学生成绩:
select min(A) AS A5 from grade where A>(select min(A) AS A4 from grade where A>(select min(A) AS A3 from grade where A>(select min(A) AS A2 from grade where A>(SELECT Min(A) AS A1 FROM grade))))
最后一步,写一个语句,取上次者之间的值,最终结果是:
select A from grade where A>=(...) and A<=(.....)
第一个括号用步骤一的语句,第二个括号用步骤二的语句,结果是:
select A from grade where A>=(select min(A) AS A3 from grade where A>(select min(A) AS A2 from grade where A>(SELECT Min(A) AS A1 FROM grade))) and A<=(
select min(A) AS A5 from grade where A>(select min(A) AS A4 from grade where A>(select min(A) AS A3 from grade where A>(select min(A) AS A2 from grade where A>(SELECT Min(A) AS A1 FROM grade)))))
结果经过验证,没有问题.
select min(A) AS A3 from grade where A>(select min(A) AS A2 from grade where A>(SELECT Min(A) AS A1 FROM grade))
同样,将这个句嵌套五次就可以取出第五名学生成绩:
select min(A) AS A5 from grade where A>(select min(A) AS A4 from grade where A>(select min(A) AS A3 from grade where A>(select min(A) AS A2 from grade where A>(SELECT Min(A) AS A1 FROM grade))))
最后一步,写一个语句,取上次者之间的值,最终结果是:
select A from grade where A>=(...) and A<=(.....)
第一个括号用步骤一的语句,第二个括号用步骤二的语句,结果是:
select A from grade where A>=(select min(A) AS A3 from grade where A>(select min(A) AS A2 from grade where A>(SELECT Min(A) AS A1 FROM grade))) and A<=(
select min(A) AS A5 from grade where A>(select min(A) AS A4 from grade where A>(select min(A) AS A3 from grade where A>(select min(A) AS A2 from grade where A>(SELECT Min(A) AS A1 FROM grade)))))
结果经过验证,没有问题.
展开全部
select top 5 * from test
except
select top 2 * from test
或者
select * from test where id between 3 and 5
或者
select * from test where id in (3,4,5)
或者
select * from test where id=3 or id=4 or id=5
太多了!
共同学习!
except
select top 2 * from test
或者
select * from test where id between 3 and 5
或者
select * from test where id in (3,4,5)
或者
select * from test where id=3 or id=4 or id=5
太多了!
共同学习!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select
*
from
班级表
where
同学名称=''
//查询某同学
select
*
from
班级表
where
班级名称(或者班级id)=(select
班级名称(或者班级id)
from
班级表
where
同学名称='')
//同班同学
*
from
班级表
where
同学名称=''
//查询某同学
select
*
from
班级表
where
班级名称(或者班级id)=(select
班级名称(或者班级id)
from
班级表
where
同学名称='')
//同班同学
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
补充:
select * from test where id >=3 and id <= 5
select * from test where id >=3 and id <= 5
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询