Alex Betev - 1 year ago 80

MySQL Question

I have an SQL statement like this:

`SELECT`

(111.045 * DEGREES(ACOS(COS(RADIANS({$lat}))

* COS(RADIANS(lat))

* COS(RADIANS({$lon}) - RADIANS(lon)) + SIN(RADIANS({$lat}))

* SIN(RADIANS(lat))))) AS distance,

(`f1` + `f2` + `f5` + `f6`) AS sum

FROM `shops`

WHERE distance <= 25

where first part returns shops within certain distance and second part returns sum of given fields in the same row of the same table.

Both parts work separately but do not return results when combined.

Please tell me what i do wrong?

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

Don't use alias in where

```
SELECT
(111.045 * DEGREES(ACOS(COS(RADIANS({$lat}))
* COS(RADIANS(lat))
* COS(RADIANS({$lon}) - RADIANS(lon)) + SIN(RADIANS({$lat}))
* SIN(RADIANS(lat))))) AS distance,
(f1 + f2 + f5 + f6) AS sum
FROM shops
WHERE (111.045 * DEGREES(ACOS(COS(RADIANS({$lat}))
* COS(RADIANS(lat))
* COS(RADIANS({$lon}) - RADIANS(lon)) + SIN(RADIANS({$lat}))
* SIN(RADIANS(lat))))) <= 25
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**