mysql - Join Only Rows that Match A Certain Condition SQLAlchemy -
i have 2 tables: a
, b
b
has foreign key a
, b
has timestamp
field.
a
has timestamp
field. interested in difference between timestamp fields rows in a
, corresponding row in b
earliest time stamp. how compute value every row in a?
for example:
a row in a
might have 5 rows in b
(5/1/2015, 2/3/2014, 2/3/2013). interested in time difference row timestamp
of 2/3/2013.
we can join each entry , build table not seem correct approach.
edit: sorry, should have been more specific. using sqlalchemy orm.
add
where b.timestamp = (select min(timestamp) b. x x.id = b.id)
this give min timestamp record.
Comments
Post a Comment