I am trying to use calculations from previous columns in SQL. I tried using variables but had no luck. Here is what i have now:
CREATE VIEW CalculationsTable (id, deltaLat, deltaLon, a, c, d) AS
SELECT Resource.id,
RADIANS("+lat+"-Resource.lat) AS deltaLat,
RADIANS("+lon+"-Resource.lon) AS deltaLon,
(SIN(deltaLat/2)*SIN(deltaLat/2)) + COS("+lat+")
* cos(Resource.lat) * (SIN(deltaLon/2)
* SIN(deltaLon/2)) AS a,
2 * ATAN2(SQRT(a), SQRT(1-a)) AS c,
6371 *c AS d
FROM Resource AS Resource;
I keep on getting this error:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column ‘deltaLat’ in ‘field list’
The deltaLat in the error is the deltaLat from this part of the code "(SIN(deltaLat/2)..."
You could try to reformat your query and use a subtable. E.g.
For your query you have to do it several times.