Oracle Data Group ranking

Source: Internet
Author: User
In the recent project, a group ranking problem occurs as follows:

The database has the following table:
Depart a B C group

detachment 1 34.4 3.3 1
detachment 1 33.3 32.2 1
detachment 3 2 3.3 22.2 1
detachment 4 3.3 4.4 33.3 1
high-tech Zone 2.2 3.3 22.2 2
Economic Development Zone 3.3 23 33.3 2
Qujiang district 4.5 35 23.9 2
weiyang district 12.2 39 3.3 2
Chang 'an district 30.3 23 2.2 2

I want to use statements to implement the following functions. The following table is returned using statements:
Depart a B C group Total ranking

Detachment 2 1 33.3 32.2 1 66.5 1
4 detachment 3.3 4.4 33.3 1 41 2
One detachment 1 34.4 3.3 1 38.7 3
Third Detachment 2 3.3 22.2 1 27.5 4
Qujiang district 4.5 35 23.9 2 63.4 1
Economic Development Zone 3.3 23 33.3 2 59.6 2
Chang 'an district 30.3 23 2.2 2 55.5 3
Weiyang district 12.2 39 3.3 2 54.4 4
Hi-Tech Zone 2.2 3.3 22.2 2 27.7 5

solution:
select *
from
(select. *, nvl (. b, 0) + nvl (. c, 0) total score
, row_number () over (partition by group order by nvl (. b, 0) + nvl (. c, 0) ranking
from tb a
)
order by group, ranking

Related Article

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.