aretherecookies-mobile/sample-query.sql

18 lines
614 B
MySQL
Raw Permalink Normal View History

2017-10-22 10:09:27 -05:00
SELECT
2017-11-11 20:15:19 -06:00
f.id AS id,
f.name AS name,
f.place_id AS place_id,
f.category AS category,
f.images AS images,
f.thumbImage AS thumbImage,
ST_AsGeoJSON(f.loc) AS location,
ST_Distance(f.loc, ST_SetSRID(ST_Point(-97.7286718, 30.3033267),4326)::geography) / 1609 AS distance,
q.quantity AS quantity,
q.date AS lastUpdated
FROM food_items f
LEFT OUTER JOIN latest_quantities q
2017-11-11 20:15:19 -06:00
ON f.id = q.food_item_id
WHERE ST_DWithin(loc, ST_SetSRID(ST_Point(-97.7286718, 30.3033267),4326)::geography, 20 * 1609)
AND f.category IN ('desserts', 'beverages', 'entrees', 'other')
2017-10-22 10:09:27 -05:00
ORDER BY distance ASC;