Mistakes from my side.
It should be read
But i would like to get the line with "Mensualité No..."  instead of
the line  with "AGIO PRETS" for the LOGEMENT_PRET budget because the
last operation by date is the

ID BUDGET AMOUNT DATE TITLE
1 LOGEMENT_PRET 990.0 2011-11-29  Mensualité No... 980.0

and not the

ID BUDGET AMOUNT DATE TITLE
8 LOGEMENT_PRET 990.0  2011-11-28  AGIO PRETS 120.0




On 29 nov, 17:27, Manakel <[email protected]> wrote:
> Hello,
>
> I'm writing my first app with Web2py.
> So far, i'm very impressed.
> But i'm facing a problem of query design:
>
> I have the following model for "operations"
> DATE BUDGET TITLE AMOUNT
> where the possible values for budget are defined in a "budget_types"
> table (budget is a reference field)
>
> I need to get the last operation by budget from the "operations" table
> (last operation would be the last by date , then by id in case of
> operations on the same date).
>
> I'm able to do the following
>
> last_operation_per_budget=db(db.operations.date.month()==current_month).sel­ect(db.operations.date,db.operations.budget,db.operations.title,db.operatio­ns.amount,groupby=db.operations.budget,orderby=
> ~db.operations.date|~db.operations.id)
>
> And here is the result
> last_operation :
> operations.date operations.budget operations.title operations.amount
> 2011-11-30 ECONOMIE_VACANCES Contribution ... 10
> 2011-11-29 NOURRITURE Repas Emma 4.5
> 2011-11-28 LOGEMENT_PRET AGIO PRETS 120
> 2011-11-28 TRANSPORTS Essence WG  50
>
> But i would like to get the line with "Mensualité No..."  instead of
> the line  with "AGIO PRETS" for the LOGEMENT_PRET budget because the
> last operation by date is the
>
> ID BUDGET AMOUNT DATE TITLE
> 8 LOGEMENT_PRET 990.0  2011-11-28  AGIO PRETS 120.0
>
> and not the
> ID BUDGET AMOUNT DATE TITLE
> 1 LOGEMENT_PRET 990.0 2011-11-29  Mensualité No... 980.0
>
> I 'm thinking about using first() or last() but i don't know how to
> insert into my existing query.

Reply via email to