I need to compare all rows in a table and need to do some calculation on every comparison.

For eg: I have 3 users(a,b,c).I need to compare a->b and give some marks to b and insert this in another table and then a->c do the calculation and store in the above same table and then need to compare b->c and do the calculation and insert the calculated value to a table.then c->a,c->b,-a do same as above.

id,userid,lat,lng is the table structure. I need to return lat and lng in each comparison ( I mean When I do a user to user) and then assign a value to second user as described above.id is pk and userid will be a non repeat value and its unique .Basically while returning lat and lng I need to check the distance calculation for each users based on one to one comparison and giving marks based on the distance then storing these marks in another table based on the user id.

How can we do these kind of comparison ? should I Use cursor ? any other simple ways ?

I am able to write a simple join query like this but no idea how to do calculation and insert this into another table.

Select * from table t1 join table t2 on t1.userid!=t2.userid