1
對Rank()函數的我(有限)理解是,如果n行匹配分區條件,則基於排序,第一組不匹配的行獲得1的等級,然後該1的集合被加起來用於下一個等級的行。它如何進入2級?在下面的數據集中,我有3排等級9(3匹配的行),下一個等級是12(9 + 3 = 12),然後我有12行的2行(2行匹配12行)和下一行等級是14.我不明白1級和2級的行。增加這些行的行列的過程是什麼?Oracle pl/sql - Rank()函數如何評估
這裏是我的源代碼
select Pos_ID, work_city, organization
RANK() OVER (PARTITION BY work_city ORDER BY organization) rnk
from DDTMS.POSITIONS
where pos_ID < 14800 order by rnk;
,這裏是一個(部分)數據集的結果(我加的期限,以保持它有點格式化以方便查看 - 第一行是一個標題行)
POS_ID WORK_CITY___________ ORGANIZATION________ RNK
14741 QUANTICO............ HQ US MARINE CORPS.. 1
14765 REDSTONE ARSENAL.... US ARMY AVN & MISSLE 1
14769 SAN DIEGO........... SPACE & NAVAL WARFAR 1
14776 THE HAGUE........... USD(COMPTROLLER).... 1
14790 VICKSBURG........... U S ARMY ENGR RESEAR 1
14732 WARREN.............. US ARMY TANK-AUTOMOT 1
14777 WASHINGTON.......... HQUSACE MILITARY PRO 1
14774 WASHINGTON NAVY YARD COMMANDER, NAVAL INS 1
14771 WRIGHT PATTERSON AFB AF AUDIT AGENCY..... 1
14749 EGLIN AFB........... AIR ARMAMENT........ 2
14764 WRIGHT PATTERSON AFB AF MUSEUM........... 2
14789 ARLINGTON........... AS(LOGISTICS & MATER 2
14783 ABERDEEN PROV GRND.. USA EDGEWOOD CHEM AN 2
14779 FORT BELVOIR........ DLA LOGISTICS OPERAT 2
14735 WASHINGTON.......... NAVSEA HQ FIELD SUPP 2
14733 PENTAGON, ARLINGTON. IMMEDIATE OFC OF CHI 2
14738 PENTAGON, ARLINGTON. IMMEDIATE OFC OF CHI 2
14762 FORT MEADE.......... DISA, GIG OPERATIONS 2
14739 WASHINGTON NAVY YARD PEO FOR SUBMARIN.... 2
14737 ARLINGTON........... ASD(ASIAN & PACIFIC. 3
14775 ABERDEEN PROV GRND.. USA HQ COMM ELECT CM 3
14731 FORT BELVOIR........ OFC OF THE CHIEF OF. 3
14729 ARLINGTON........... DEFENSE SECURITY COO 4
14745 ARLINGTON........... DIR, COST ASSESSMENT 5
14736 ARLINGTON........... HQDA, ODCSLOG....... 6
14788 ARLINGTON........... HQDA, OSA, OFC OF TH 7
14760 ARLINGTON........... OASD (HOMELAND DEF & 8
14740 ARLINGTON........... OASD (SO/LIC & INTER 9
14773 ARLINGTON........... OASD (SO/LIC & INTER 9
14743 ARLINGTON........... OASD (SO/LIC & INTER 9
14750 ARLINGTON........... OASD(ISA)........... 12
14751 ARLINGTON........... OASD(ISA)........... 12
14778 ARLINGTON........... OFC ASST SECY OF ARM 14
14746 ARLINGTON........... OFC DIR, ADMIN/MGMT. 15
14753 ARLINGTON........... OFC GEN COUNSEL..... 16
14734 ARLINGTON........... OFC SEC OF DEF...... 17
14768 ARLINGTON........... OFFICE OF NAVAL RESE 18
14781 ARLINGTON........... ONI................. 19
14757 ARLINGTON........... U S AIR FORCE....... 20
14763 ARLINGTON........... U S AIR FORCE HQ.... 21
我通過查詢外部分留出了RNK別名和秩序。剛剛更新了。 –
我認爲'RANK()'的方式是返回比當前記錄更早/更小的記錄數加1.因此,rank = 1意味着早於/小於當前記錄的記錄數爲零; rank = 2表示比當前記錄更早/更小的記錄正好有1個記錄;等級12意味着有11個記錄提前/小於當前記錄。 –