create table stuScore
(
stuid int,
classid int,
score int
)
----------------------------
如何获取每个classid的前5条呢,score可能有重复的情况。
select * from stuscore s
where 5>(select count(*) from stuscore where classid=s.classid and score>s.score)
order by classid
用上面的sql会把score重复的数据也查询出来,求教怎么查询出固定的呢
5 个解决方案
#2
select * from stuscore s
where 5>(select count(*) from stuscore where classid=s.classid and stuid>s.stuid)
order by classid
where 5>(select count(*) from stuscore where classid=s.classid and stuid>s.stuid)
order by classid
#3
如果我想根据score排序呢,如果有重复的还是取前5条
#4
select * from stuScore Oder by classid limit 0,5
#5
#1
#2
select * from stuscore s
where 5>(select count(*) from stuscore where classid=s.classid and stuid>s.stuid)
order by classid
where 5>(select count(*) from stuscore where classid=s.classid and stuid>s.stuid)
order by classid
#3
如果我想根据score排序呢,如果有重复的还是取前5条
#4
select * from stuScore Oder by classid limit 0,5