比如一张表
create table st(name varchar(10),score int);insert into st
select 'a',98
union all
select 'b',90
union all
select 'c',80
union all
select 'd',80
union all
select 'e',71
union all
select 'f',75
union all
select 'g',80
union all
select 'h',74写出排名前3的.结果是:
学生 成绩
a 98
b 90
c 80
d 80
g 80
同分排名一样,给出的sql语句为:
select a.* from st a where 3 >(select count(*) from st where score > a.score)
对于上面的语句我不是很理解,请哪位高手帮我分析下..
特别是 3 >(select count(*) from st where score > a.score);
3可以理解为排名前3的,而 (select count(*) from st where score > a.score)这个的用处是什么.有点迷糊,
请哪位高人指点....
create table st(name varchar(10),score int);insert into st
select 'a',98
union all
select 'b',90
union all
select 'c',80
union all
select 'd',80
union all
select 'e',71
union all
select 'f',75
union all
select 'g',80
union all
select 'h',74写出排名前3的.结果是:
学生 成绩
a 98
b 90
c 80
d 80
g 80
同分排名一样,给出的sql语句为:
select a.* from st a where 3 >(select count(*) from st where score > a.score)
对于上面的语句我不是很理解,请哪位高手帮我分析下..
特别是 3 >(select count(*) from st where score > a.score);
3可以理解为排名前3的,而 (select count(*) from st where score > a.score)这个的用处是什么.有点迷糊,
请哪位高人指点....
解决方案 »
- 菜鸟求:MySQL存储图片能够自行输入吗?还是用程序实现?
- 把数据库拷贝到data文件夹下,但是数据库里不显示
- 解析字符串问题,100100000101011111010101解析出111
- 十万火急!关于C++操作MYSQL的语句!
- MySQL中delete from table_name where id = (select Max(id) from table_name);执行错误是怎么回事
- Access denied for user错误?
- 请问哪里可以下载mysql
- .........100分求crystal reports 9.0的注册码
- mysql WHERE查询机制
- 对表中的记录分组,并求每组所占百分比
- 请教key与index的问题
- mysql时间戳
select a.* from st a where 3 >(select count(*) from st where score > a.score)
或则是另有一办法实现这效果吗.
能理解吗?如果能,则
select count(*) from st where score > a.score
你是如何理解的?如果能,则
3 >(select count(*) from st where score > a.score)你是如何理解的?
那where 3 是不是就是根据,count(*)出来后的结果来自己添加的呢.
=
select count(*) from st where score > 80结果是几? 2!where 3 >(select count(*) from st where score > a.score)
=
where 3 >(2)
就是3(或则是其他数字)的话,是不是就取决于后面count(*)出来的数字,如按照需求count(*)出来的是5,就应该 where 6 ? 是这样吗.