Hi villas,
perhaps my "problem" is: if you group/aggregate in SQL, you are allowed
only to put attributes in the select-clause which are either grouped (i.e.
which also appear in the group-clause) or which are aggregated (e.g. with
sum, max, min, avg) at least as far as my knowledge goes. The f
Ok, with the DAL I solved it in the following way and did the join
"manually":
# get last val_date for each prop
maxdate = db.prop_val.val_date.max().with_alias('max_val_date')
rows1 = db().select(db.prop_val.prop_id.with_alias('prop_id'), maxdate,
groupby=db.prop_val.prop_id)
#
Hi villas,
thanks for your example but that delivers the wrong result. With your query
we get
name date amount
aaa 2016-01-15 15
bbb 2016-01-20 10
ccc 2016-01-25 29
The result with your data should be (perhaps with additional price column)
name date
Hi villas,
thanks for your comment and the links (especially the second one).
Since I want to learn if you can show me a better solution in SQL I would
highly appreciate it. Normally I prefer do write my SQL "stepwise" so I
don't have to read inside out. Here's a small SQLite setup:
-- setup
Hello,
I've got a problem and don't know if it's (easily) solvable in web2py.
There're two tables, one for properties and one for their valuations (one
property can have zero to multiple valuations):
db.define_table('property',
Field('property_id', 'id'),
5 matches
Mail list logo