Hello,

I have the following models for "Operations".
db.define_table('operations',Field('date','date'),Field('budget',db.budgets),Field('title','string'),Field('amount','double'),format='%
(budget)s-%(amount)d-%(date)s:%(title)s')


I'm performing the following query to get the total amount of
operations for 1 budget within the month.
monthly_amount_per_budget=db((db.operations.budget==budget['id'])&
(db.operations.date.year()==current_year) &
(db.operations.date.month()==current_month)).select(db.operations.amount.sum().coalesce_zero(),
groupby=db.operations.budget)

So i get the expected results
LOGEMENT_PRET : COALESCE(SUM(operations.amount),0)
1100

NOURRITURE : COALESCE(SUM(operations.amount),0)
24.0

Now i would like to store only the value "1100" in a variable, but how
to get this value?
I've tried and failed with:
   monthly_amount_per_budget.first()[sum]
   monthly_amount_per_budget.first()[db.operations.amount.sum]
   monthly_amount_per_budget.first()['COALESCE(SUM(operations.amount),
0)']
etc...

Thanks a lot for your help. I have hard time trying to make sql from
python code (too much used to direct SQL))


Reply via email to