jeudi 30 avril 2015

Write Java Code to execute SQL Group By

We would typically write Oracle SQL to find max salary of every employee in each department if we had a table with EmpID, DeptID, Salary:

select EmpID,DeptID, rank over(partition by DeptID order by Salary) rnk
from Table
where rnk=1;

OR

select EmpID
from Table1
where Salary =(Select max(Salary) from Table2 group by DeptID
               and Table2.DeptId = Table1.DeptId )

If the above table was a file instead, then how can we write custom Java code to implement the same behavior?

Aucun commentaire:

Enregistrer un commentaire