When timeseries and GIS data is in the same place, it can be queried using a single expression.
SELECT time_bucket('1 day', time) AS day,
COUNT(*) AS trucks_exiting,
SUM(weight) / 1000 AS tonnage
FROM vehicles
INNER JOIN cities ON cities.name = 'los_angeles'
WHERE ST_Within(last_location,
ST_Polygon(cities.geom,4326))
AND NOT ST_Within(current_location,
ST_Polygon(cities.geom,4326))
GROUP BY day
ORDER BY day DESC LIMIT 30;