FROM ta1 AS a
WHERE score in(select top 3 score from ta1 where class=a.class order by score desc);
可是数据量大时会出现查询缓慢而且结果混乱的现象
不知道能将上面这个拆成两个步骤来执行.
5 个解决方案
#1
已上传测试文件到:
http://access911.net/csdn/FileDescription.asp?mdb=2011-3-24&id=30
http://access911.net/csdn/FileDescription.asp?mdb=2011-3-24&id=30
#2
SELECT a.*
FROM ta1 AS a
where 3<=(select count(*) from ta1 where class=a.class and a.score<=score)
在class、score上建立索引
FROM ta1 AS a
where 3<=(select count(*) from ta1 where class=a.class and a.score<=score)
在class、score上建立索引
#3
执行更慢了.....5~
#4
你的SCORE有重复
select a.* from ta1 a inner join (
select * from (
SELECT class,score from ta1 group by class,score) a
where 3>(select count(*) from
(SELECT class,score from ta1 group by class,score) where
a.class=class and a.score<score)) b
on a.score=b.score and a.class=b.class
select a.* from ta1 a inner join (
select * from (
SELECT class,score from ta1 group by class,score) a
where 3>(select count(*) from
(SELECT class,score from ta1 group by class,score) where
a.class=class and a.score<score)) b
on a.score=b.score and a.class=b.class
#5
#1
已上传测试文件到:
http://access911.net/csdn/FileDescription.asp?mdb=2011-3-24&id=30
http://access911.net/csdn/FileDescription.asp?mdb=2011-3-24&id=30
#2
SELECT a.*
FROM ta1 AS a
where 3<=(select count(*) from ta1 where class=a.class and a.score<=score)
在class、score上建立索引
FROM ta1 AS a
where 3<=(select count(*) from ta1 where class=a.class and a.score<=score)
在class、score上建立索引
#3
执行更慢了.....5~
#4
你的SCORE有重复
select a.* from ta1 a inner join (
select * from (
SELECT class,score from ta1 group by class,score) a
where 3>(select count(*) from
(SELECT class,score from ta1 group by class,score) where
a.class=class and a.score<score)) b
on a.score=b.score and a.class=b.class
select a.* from ta1 a inner join (
select * from (
SELECT class,score from ta1 group by class,score) a
where 3>(select count(*) from
(SELECT class,score from ta1 group by class,score) where
a.class=class and a.score<score)) b
on a.score=b.score and a.class=b.class