S) How to find dept wise 2nd and 3rd highest salary .
Sort : Dept-Asc
Salary-Desc
Scan
Key –Dept
Let decimal (“ “) rank =0;
Type temporary type =
Record
Decimal(“|”) count ;
End;
Temp :: initialize(in)=
Begin
Temp. rank=0;
Temp.count :: 0;
End;
Temp::scan(temp,in)=
Begin
Rank =(if(temp.count=in.sal)rank else rank +1;
Temp.count ::temp.count+1;
End;
Temp :: finalize(temp,in)=
Begin
Out.* ::in.* ;
End;
Out ::output_select(out)=
Begin
Out ::rank ==2 or rank ==3;
End;
Note :- If any dept doesn’t have 3 rd highest or 2nd highest then also above code will work , but in output that dept data will not come
Comments
Post a Comment