server side query processing

Separated queries:
- common query for data common for all legs under one trip
- query for all legs
Both are tied together by trip_id.