0

This doesn't answer my question.

I have found a query like this for searching objects in a circle.

SELECT id, ST_X(location),ST_Y(location), state
FROM (
SELECT id, location, state, r,
units * DEGREES( ACOS(
COS(RADIANS(latpoint))
* COS(RADIANS(ST_X(location))) 
* COS(RADIANS(longpoint) - RADIANS(ST_Y(location)))
+ SIN(RADIANS(latpoint))
* SIN(RADIANS(ST_X(location))))) AS distance
FROM fountains
JOIN (
SELECT 13.1  AS latpoint, 2 AS longpoint,
 1000  AS r, 111.045 AS units 
) AS p ON (1=1)
WHERE MbrContains(ST_GeomFromText(
CONCAT('LINESTRING(',
latpoint-(r/units),' ',
longpoint-(r /(units* COS(RADIANS(latpoint)))),
',',
latpoint+(r/units) ,' ', 
longpoint+(r /(units * COS(RADIANS(latpoint)))),
')')),  location)
) AS d
WHERe d.distance <= d.r HAVING d.state="faulty" 
ORDER BY d.distance ASC;

This is the result on my database:

id  ST_X(location)  ST_Y(location)  state
2   13.1            2.1             usable
1   13              2               faulty
3   13.2            2.2             usable
5   13.3            2.3             usable
6   12.9            2.3             usable

How to add a clause to add a condition on the result? Like if I want to have only the records with the column state=="usable"?

I see also that if I go on localhost:xxxx and enter in my db, with a where clause or an having clause I can do it, but with my GO lang server, I cant.

edoardottt
  • 100
  • 1
  • 11
  • 1
    `WHERe d.distance <= d.r and state IN( 'usable','faulty')` -- however, there is no d.distance here, so something doesn't add up - Please see: [Why should I provide an MCRE for what seems to me to be a very simple SQL query?](https://meta.stackoverflow.com/questions/333952/why-should-i-provide-a-minimal-reproducible-example-for-a-very-simple-sql-query) – Strawberry Feb 28 '20 at 10:47
  • Thanks, This answered well my question – edoardottt Feb 28 '20 at 12:09

1 Answers1

0

WRONG SYNTAX. Thanks to strawberry

edoardottt
  • 100
  • 1
  • 11