I have the following query where I want to calculate the closest user to a building of type "store":
WITH y AS (
SELECT t.userid as us, ST_Distance(t.thegeometry,b.thegeomtry) as dist
FROM track t,buildings b
WHERE b.type = 'store'
)
SELECT us
FROM y
WHERE dist = (SELECT MIN(dist) FROM y)
The problem is when I tried to compute the minimum it gives me 0 which is not true. In my data the minimum distance between user with id 112 and store A equals 2441 meters.