Hi!
again about this old question... I tried to work around this not so easy problem but I always came back to it.

the solution proposed by howesc runs but not resolves my needs. Now suppose I need to extract another value of the curve record corresponding to the max start value... how can I do?

I cannot simply insert in the select fields list because it couses an error like that:

ProgrammingError: column "<column name>" must appear in the GROUP BY clause or be used in an aggregate function

Thanks a lot

    Manuele

On 27/07/2011 00:23, howesc wrote:
not sure about the web2py translation (that would take me some time to figure out since i have not done much grouping in web2py), but:

SELECT * FROM (SELECT * FROM power_curve ORDER BY start DESC) AS TMP
GROUP BY site;

is not valid. i'm surprised that it works on mysql server. every column that appears in the select must be aggregated or part of the group by clause for the query to be valid.

based on a counting query i have done in the past:

start_max = db.curve.start.max()
db((db.curve.site==db.site.id)).select(start_max, db.site.id, groupby=db.site.id)

does that work, or at least get you started?

cfh

Reply via email to