# Print Minimum & Maximum Salary of Respective Employee

I have an input file in the below format :
NAME SAL
---- ---
A 4000
B 3000
C 8000
A 2000
B 7000
C 5000
B 2000
C 9000
A 1000

If I will use Sort ---> Aggregator Group by then it will give 3 columns like NAME,MAX(),MIN()
NAME MAX() MIN()
---- ----- -----
A 4000 1000

But my requirement is to generate the output which will give the maximum & minimum salary in a single col w.r.t the employees.Like below :
NAME SAL(Sal column will contain only minimum and maximum salary for respective employees)
NAME SAL
---- ---
A 4000
A 1000
B 7000
B 2000
C 9000
C 5000

#### Nick

• Aug 6th, 2016

Use separate agg stage for Min and Max. Then Funnel the two outputs and sort by name.

#### shibiya joseph

• Oct 24th, 2016

First we have to use two rollup function for min and max then concatenate the two outputs and sort by name.

#### Anil

• Oct 25th, 2016

A) SeqFile --> Copy ----> Remove duplicate1 for Minimum sal - Peek1
|
|
v
Remove duplicate2 for Maximim sal - Peek2

1.In remove duplicate stages, take Name as Key, Partiton and sort by Name, Sal in Ascending order
2.In Remove duplicate1, use retain first value to get minimum value.
3.In Remove duplicate2, use retain last value to get maximum value.

• Dec 14th, 2016

#### Neha

• Apr 7th, 2017

Use Seq File->Aggregator Stage (group by Salary, Emp_Name and find min, max salary)->use Pivot(horizontal Pivot)

#### Sirisha d Profile Answers by Sirisha d

• Apr 18th, 2017

Job Design :
Sequential File --> Aggregator --> Transformer --> Sequential File
Aggregator :
Group by - EmpName
Col for Calculation - Salary
Generate two columns - one for maximum salary (Max()) and one for minimum salary (min())
Hash partitioning and sort by EmpName
Transformer :
Define 2 loop variables.
LoopVar1 - Input col(EmpName)
LoopVar2 - If @ITERATION=1 Then Max_Sal Else Min_Sal
In the Loop While condition, give @ITERATION>0 and @ITERATION<=2
assign LoopVar2 to Salary column.
This gives the minimum and maximum salary of an employee in separate rows in the same column.