I have the data in my table like below structure,
Manager Id Employee id chartfield
SM1 MGR-1 12
SM2 MGR-1 12
MGR-1 LEAD-1 12
MGR-1 LEAD-2 12
MGR-1 LEAD-3 12
LEAD-1 LEAD-2 12
LEAD-1 ASSOCIATE -1 12
LEAD-1 ASSOCIATE -2 12
LEAD-2 LEAD-3 12
LEAD-2 ASSOCIATE -3 12
LEAD-2 ASSOCIATE -4 12
LEAD-3 ASSOCIATE -5 12
LEAD-3 ASSOCIATE -6 12
ASSOCIATE -1 JUNIOR - 1 12
ASSOCIATE -1 JUNIOR - 2 12
ASSOCIATE -2 JUNIOR - 1 12
ASSOCIATE -2 JUNIOR - 2 12
I am expecting output with manager and employees with the levels they are present. The only criteria here is same employee could report to multiple managers and this case we should select only distinct employees who is reporting to that employees with least level. In the above case LEAD-2 is reporting to MGR -1 and LEAD-1 but we are considering the least level.
The sample output could be like below structure,
Manager Id Employee id chartfield LEVEL1
MGR-1 LEAD-1 12 1
MGR-1 LEAD-2 12 1
MGR-1 LEAD-3 12 1
MGR-1 ASSOCIATE -1 12 2
MGR-1 ASSOCIATE -2 12 2
MGR-1 ASSOCIATE -3 12 2
MGR-1 ASSOCIATE -4 12 2
MGR-1 ASSOCIATE -5 12 2
MGR-1 ASSOCIATE -6 12 2
MGR-1 JUNIOR - 1 12 3
MGR-1 JUNIOR - 2 12 3