Sql-leetcode 178. Rank Scores

Source: Internet
Author: User

Score is well received: Select score from Scores ORDER by score Desc;

To get rank, you can get by comparing the number of score that are larger than the current score:

Select Score, (select COUNT (Distinct score) from Scores where Score>=s.score) Rank where Scores s order by score Desc;

  

Or:

Select S.score, COUNT (distinct T.score) Rank from Scores s join Scores t on S.score<=t.score

Get a join two tables,

{"Headers": ["Score", "score"], "values": [[3.50, 3.50], [3.50, 3.65], [3.65, 3.65], [3.65, 3.65], [3.50, 4.00], [3.65, 4. 00], [4.00, 4.00], [3.85, 4.00], [4.00, 4.00], [3.65, 4.00], [3.50, 3.85], [3.65, 3.85], [3.85, 3.85], [3.65, 3.85], [3.50 , 4.00], [3.65, 4.00], [4.00, 4.00], [3.85, 4.00], [4.00, 4.00], [3.65, 4.00], [3.50, 3.65], [3.65, 3.65], [3.65, 3.65]]}

Press S. The IDs are gathered together:
Select S.score, COUNT (distinct T.score) Rank from Scores s join Scores t on S.score<=t.scoregroup by S.idorder by S.scor E desc

  







Sql-leetcode 178. Rank Scores

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.