MySQL ranking query

Source: Internet
Author: User

-- ------------------------------------------------------------the structure of the table ' score '--CREATE TABLE IF  not EXISTS' score ' (' ID ')int( One) not NULLauto_increment, ' name 'varchar( +) not NULL DEFAULT "', ' scores 'int( One) not NULL DEFAULT '0',  PRIMARY KEY(' id ')) ENGINE=MyISAMDEFAULTCHARSET=UTF8 auto_increment=6 ;----dump the data in the table ' score '--INSERT  into' Score ' (' id ', ' name ', ' scores ')VALUES(1,'a', the),(2,'b', -),(3,'C',98),(4,'D', the),(5,'e', the);SelectA.name, A.scores, (Select Count(ID) fromScorewhereScores>=A.scores) asMC fromScore a limit0,TenSelect *  from (SelectA.name, A.scores, (Select Count(ID) fromScorewhereScores>=A.scores) asMC fromscore a) bwhereB.mc<=TenSelect *  from(Select(Select Count(ID)+1   fromScorewhereScores>A.scores) asMc,a.name, A.scores fromScroe a) bwhereB.mc<=Ten    Order  byB.mc

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.