I was studying SQL and found the following question:
What is the result of the following query:
SELECT SUM (V2.VALOR - V.VALOR)
FROM VIAGEM AS V INNER JOIN VIAGEM AS V2
ON (V.VALOR = V2.DISTANCIA / 100)
And the table:
Viagem Valor Distancia 3 200 4 100 2 500 12 400 4 300 3 200 12 100
The answer is 20, but, I did not quite understand the operation. I put the script to run, I did some tests, but I did not quite understand the operation. My reasoning was as follows:
For each value of V.Valor I will compare with each of the other values of distances / 100.
For example:
For the first value of my table V, I will compare with each (v2.distance / 100) to see if they are equal, and so I am putting together the resulting tables in order to make the sum difference. Is that it?