I need formula for Calculating Required net Run rate for a group match. .

For EG: in a Group there are 3 teams. All Teams will won one one match each .. and in the last match what is the margin to win for every team to qualify for Next round. .

SAMPLE DATA :

TEAM-1 Runs Over BALLS RR TEAM-2 Runs Over BALLS RR RESULT
ABC 48 8 48 6.00 v/s XYZ 42 8 48 5.25 ABC Won by 6 Runs
ABC 59 8 48 7.38 v/s PQR 67 8 48 8.38 PQR Won by 8 Runs
XYZ PQR


last match is with XYZ and PQR ... if XYZ win this match , there are chances of qualifying through NRR for 2 Teams. Formula Required for below scenarios .

1. MARGIN RUNS TO QUALIFY FOR PQR if they bat 1st
2. MARGIN Win by runs to qualify for PQR if they bat 2nd
3. MARGIN RUN TO QUALIFY FOR ABC ( based on the runs these 2 team score)
4, MARGIN RUNS TO QUALIFY FOR XYZ if they bat 1st or 2nd

Pls provide some formula for these calculations..