MarcelloWrites
MarcelloWrites

Reputation: 43

Calculate row datas and select them

Below is what I have in the table 'myTable':

COMPANY pointX pointY
MICROSOFT 12.434 76.810
AMAZON 1.779 290.122
APPLE 601.840 333.910

What I have to do is set MICROSOFT as the datum point,

and calculate the distance between each company and sum them in a new column.

I tried to make a query, but I guess it's a bit complex for me.

Upvotes: 0

Views: 58

Answers (1)

forpas
forpas

Reputation: 164099

Use a self join:

SELECT t1.COMPANY,
       ABS(t2.pointX - t1.pointX) + ABS(t2.pointY - t1.pointY) DISTANCE
FROM myTable t1 INNER JOIN myTable t2
ON t2.COMPANY <> t1.COMPANY
WHERE t2.COMPANY = 'Carlos';

See the demo.

Upvotes: 1

Related Questions