Sorry if this is a strange question, I’ve been going through the docs/tutorial on the sqlalchemy site but I can’t figure out how to do this specific query.
I have a bunch of dates of activity on my site that continues until changed. I know I can query specific dates or ranges of dates but what if I query a date(which doesn’t exist) can I get the previous match?
For example say I have june 25, and june 30, as two dates, I run a query for June 29. Is it possible to get the June 25th data with only one query? I just want the previous match of a date I enter.
Below is probably a simplified version of your model, but hopefully the example will help you create your own query.
Assuming the model is defined as below, and that the
[Activity.person_id, Activity.date]is unique (basically, only one activity per day is allowed), the query using a subquery, which returns tuples(Person, _last_ Activity):