So why can't you do something like this...
db.define_table('prop',
Field('name','string'),
Field('price','integer'),
)
if not db(db.prop.id>0).count():
db.prop.insert(name="aaa", price=10)
db.prop.insert(name="bbb", price=15)
db.prop.insert(name="ccc", price=20)
db.define_table('prop_val',
Field('prop_id','reference prop'),
Field('val_date',length=8),
Field('amount','integer'),
)
if not db(db.prop_val.id>0).count():
db.prop_val.insert(prop_id=1, val_date="2016-01-01", amount=1)
db.prop_val.insert(prop_id=1, val_date="2016-01-15", amount=15)
db.prop_val.insert(prop_id=2, val_date="2016-01-01", amount=10)
db.prop_val.insert(prop_id=2, val_date="2016-01-20", amount=6)
db.prop_val.insert(prop_id=3, val_date="2016-01-01", amount=29)
db.prop_val.insert(prop_id=3, val_date="2016-01-25", amount=25)
maxdate = db.prop_val.val_date.max()
maxval = db.prop_val.amount.max()
rows = db(db.prop.id ==
db.prop_val.prop_id).select(db.prop.name,maxdate,maxval,groupby=db.prop.name)
for r in rows: print r
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.