Group by unique pairs with no multiplicity
With full_Group_on you can use for example this, if a &quot;_&quot; is not present  your columns
CREATE VIEW EFFICIENCY AS
SELECT SUBSTRING_INDEX(area_driver, '_', 1) as AreaID,SUBSTRING_INDEX(area_driver, '_', -1) AS DriverID, AvgPrice
 FROM (SELECT CONCAT(AreaID,&quot;_&quot;,Bookings.DriverID) area_driver, AVERAGE(Bookings.Fare/Bookings.Miles) AvgPrice
 FROM AreaLocations
 RIGHT JOIN Bookings ON
 ( AreaLocations.Location = Bookings.Location )
 GROUP BY  CONCAT(AreaID,&quot;_&quot;,Bookings.DriverID)) f1