SQL to sort multiple accounts in a single table

Source: Internet
Author: User
My classmates asked me how to sort the scores of multiple subjects in a table and write the results back to the database. the SQL statements are too simple and too stupid to be written. so I searched everywhere and found the SQL sentences that were updated at the same time in the order of single form subjects. click here if you want to view the original text.
So I made a small modification to the SQL statement to achieve my goal. In my test, the table name is ctest, and the field name is pinyin.
This is before sorting:

The SQL statement used is as follows:

Update ctest
Set mingci = (
Select count (*) + 1
From ctest
Where ctest. fenshu> A. fenshu
And ctest. Kemu = A. Kemu)
From ctest

Among them, and ctest. Kemu = A. Kemu is added to me. In this way, you can rank multiple subjects. If not, you can only think of it as a single subject.
The result is as follows:

The ranking of the same score is the same, and the subsequent ranking will be postponed. For example, there are already two ranking first, and the following is the ranking third, not the second.
I find myself too stupid, so I cannot be so lazy in the future. I should learn more about this.

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.