我需要从locations
表中获取坐标并将其替换为我的数据53.4015174, 44.967495
SELECT P.*
FROM PRODUCTS AS P
LEFT JOIN MERCHANTS AS M ON (M.MERCHANT_ID = P.STORE_ID)
LEFT JOIN CATEGORIES AS C ON (C.CATEGORIES_NAME = P.CATEGORIES)
LEFT JOIN LOCATIONS AS LO ON (LO.LOCATION_ID = 20)
WHERE P.CATEGORIES ILIKE ANY(ARRAY['Cameras']) AND
ST_DWithin(M.LOCATION::geography, ST_GeogFromText('POINT(53.4015174 44.967495)'), LO.RADIUS, false)
GROUP BY P.PRODUCT_ID, M.MERCHANT_ID
答案 0 :(得分:1)
将SRID正确设置为此查询4326;
SELECT ST_SetSRID(ST_MakePoint(-71.1043443253471, 42.3150676015829),4326);
SELECT P.*
FROM PRODUCTS AS P
LEFT JOIN MERCHANTS AS M ON (M.MERCHANT_ID = P.STORE_ID)
LEFT JOIN CATEGORIES AS C ON (C.CATEGORIES_NAME = P.CATEGORIES)
LEFT JOIN LOCATIONS AS LO ON (LO.LOCATION_ID = 20)
WHERE P.CATEGORIES ILIKE ANY(ARRAY['Cameras']) AND
ST_DWithin(M.LOCATION::geography, ST_AsText(ST_SetSRID(ST_MakePoint(-71.1043443253471, 42.3150676015829),4326))
GROUP BY P.PRODUCT_ID, M.MERCHANT_ID