开发者

Mysql query for finding 10 close marks of class

开发者 https://www.devze.com 2022-12-27 16:37 出处:网络
I want nearest 10 marks for particular student. For exa开发者_运维百科mple John has marks 73 then i have to find 10 student with marks greater than 73 in ascending order nearest to John. My Table stru

I want nearest 10 marks for particular student. For exa开发者_运维百科mple John has marks 73 then i have to find 10 student with marks greater than 73 in ascending order nearest to John. My Table structure is (id,name,marks).


Try this:

SELECT id, name, marks
FROM table1
WHERE marks > (SELECT marks FROM table1 WHERE name = 'John')
ORDER BY marks
LIMIT 10


Select s.id, s.name, s.marks
From students sj
Join students s On ( s.marks > sj.marks )
Where sj.name = 'John'
Order By s.marks
Limit 10

sj will be student John (assuming that you have only one John), and s contains all records with marks greater than John's.

The Limit limits the output to ten rows.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号