python - web2py DAL complex query -


i have raw sql query translate web2py dal query. possible? translating can make more inefficient?

tables are:

t_proyecto ( f_nombre, ...) t_informe  ( f_proyecto [reference t_proyecto], ....) t_gasto    ( f_nombre, f_monto, f_informe [reference t_informe]) 

the idea 1 project (t_proyecto) has many reports (t_informe) , each report can declare/have many expenses (t_gasto). want have total expenses each project.

this sql works fine, know corresponding dal expression:

result=db.executesql('select f_nombre, sum(f_monto)                       t_proyecto,                            (select f_proyecto, f_monto                              t_informe, t_gasto                              t_gasto.f_informe==t_informe.id) auxtable                         t_proyecto.id==auxtable.f_proyecto                        group t_proyecto.f_nombre;') 

i've tried several things, none seemed work, , ended writing raw sql. solve , understand logic appreciated

thanks!

i don't think can join table , subquery, should give same result

select f_nombre, sum(f_monto) t_proyecto, t_informe, t_gasto  t_gasto.f_informe==t_informe.id , t_proyecto.id==t_informe.f_proyecto  group t_proyecto.f_nombre; 

dal query:

db((db.t_proyecto.id==db.t_informe.f_proyecto) &    (db.t_informe.id==db.t_gasto.f_informe)).select(db.t_gasto.f_monto.sum(), db.t_proyecto.f_nombre, groupby=db.t_proyecto.f_nombre) 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -