Thursday, 3 July 2014

How to get top 3 salaried for each Department from Employee Table.

Approach 1 using Rank Transformation
Create the mapping as below:

Use sorter transformation to sort record order by Deptno and Sal in Ascending.
In Ranker Transformation Select Group by for Deptno, Rank value for Sal in ports tab

  and Properties tab of Ranker Transformation Select Top 3 Ranks as below 
Map required transformation the ports from Rank Transformation to Target Instance

Approach 2 using without Ranker Transformation
In Sorter Transformation select Deptno, Sal ports
 
In Expression Transformation compare current process row deptno with previous processed row, which will assign sequence number to input records for each deptno.
 
expression logic:
var_seq_dept_wise_sal = IIF(DEPTNO=var_pre_deptno, var_seq_dept_wise_sal+1, 1)

In Filter Transformation use condition to pass only 3 records from each deptno based on flag created in expression.
Map required ports from Filter Transformation to Target Instance.

4 comments:

  1. In the Approach 2, you will get only top 3 Sal of Dept 10 , you would not get other dept sal by above Approach 2

    ReplyDelete
  2. Hi Dhrumi Soni,

    This will give all the dept top 3 sal as there is no filter is happening at dept no level. Here i am created seq for 1,2,3 for each dept as flag. I am filter only seq less than equal to 3.

    Please try and let me known.

    ReplyDelete
  3. As claimed by Stanford Medical, It's in fact the ONLY reason women in this country get to live 10 years more and weigh on average 42 lbs lighter than us.

    (And actually, it has NOTHING to do with genetics or some hard exercise and absolutely EVERYTHING related to "how" they eat.)

    BTW, I said "HOW", not "WHAT"...

    Click this link to discover if this little quiz can help you decipher your true weight loss possibilities

    ReplyDelete