Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
SQL Server 119
#SQLServer 88
Oracle 70
#SQL SERVER 35
BRH 31
SQL Server 2012 29
denali 23
#TSQL 19
TSQL 19
C# 15

Archive · View All
October 2011 31
November 2011 30
September 2011 30
August 2011 18
December 2011 15
July 2011 13
June 2011 8
May 2012 4
April 2012 3
January 2010 3

Day 41: Cume_Dist Function of Oracle

Oct 24 2011 11:04PM by Niladri Biswas   

Let Us Learn Oracle - Part 41 of N [ Cume_Dist function of Oracle ]

It acts both as Aggregate and analytic function.

Analytic Example

Purpose: Within a group of rows, it calculates the cumulative distribution of a value in a group of values.

Syntax: Cume_Dist() Over ([partition_by_clause] order_by_clause)

Formula:

Cumulative_Distribution = (R)/(N)

Where,

R => The row whose rank needs to be found

N => Total number of rows or records.

e.g. We have a set with 10 elements. We need to find the cumulative distribution of the 7th row. Henceforth, applying the values to the above formula, we get R = 7 , N = 10

So, Cumulative_Distribution = (7)/(10) = 0.7

The range of values return by this function is between 0 to 1 inclusive. The return data type is always a positive number.

SQL> Select 
  2   PlayerID
  3  ,PLAYERFIRSTNAME || ' ' || PLAYERLASTNAME As PlayerName
  4  ,BelongsTo
  5  ,FeePerMatch
  6  ,Cume_Dist() Over(Partition By BelongsTo Order By BelongsTo,FeePerMatch) As  CumilativeDistribution
  7  From tblPlayers;

  PLAYERID PLAYERNAME            BELONGSTO  FEEPERMATCH CUMILATIVEDISTRIBUTION
---------- --------------------- ---------- ----------- ----------------------
         4 D Das                 India              500             .166666667
         2 B Kadir               India             1000             .333333333
         1 A Raman               India             2000                     .5
         3 C Nadir               India             3000             .666666667
         5 E Punchkar            India            12000             .833333333
        11 P Chopra              India                                       1
         7 G Gajani              USA                999                     .2
         9 I Ikat                USA               5999                     .4
         8 H Hariharan           USA               7000                     .6
        10 J Jwar                USA               7900                     .8
         6 F Fateman             USA              22000                      1

11 rows selected.

Now let us understand how the relative rank for the [Fee Per Match] column has been generated.

Take the case of the row where the Player ID is 1 i.e. 3rd from the row.

There are altogether 6 rows for the [Belongsto] field "India".

So , we have R = 3 and N = 6.

Placing the values in our formula yields

Cumulative_Distribution = 3/6 = 0.5

Aggregate Example


SQL> Select Cume_Dist(2000,.09)
  2  Within Group
  3  (Order By SAL,COMM) Percent_Rank
  4  From Emp;

PERCENT_RANK
------------
          .6

Prior to Denali CTP3, there was no inbuilt Cume_Dist function.But we have this now in the form of Aanlytical function.You can read about Cume_Dist of Sql Server from here

Hope you have enjoyed it.Thanks for reading

Tags: #SQLServer, SQL Server, Oracle,


Niladri Biswas
7 · 21% · 6710
1
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

"Day 41: Cume_Dist Function of Oracle" rated 5 out of 5 by 1 readers
Day 41: Cume_Dist Function of Oracle , 5.0 out of 5 based on 1 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]