grouping and summing with sorting

21 views
Skip to first unread message

黄祥

unread,
Oct 14, 2021, 5:13:26 PM10/14/21
to web2py-users
modules function
def report_vars_10(table_name, field_group, field_calc, query):
    table_field_group = current.db[table_name][field_group]
    table_field_calc = current.db[table_name][field_calc]
    table_field_sum = table_field_calc.sum()
    rows = current.db(query).select(table_field_group, table_field_sum, 
                                    groupby = table_field_group)
    grouping_calc = {}
    for row in rows:
        grouping_calc[row[table_name][field_group] ] = row[table_field_sum]
    return grouping_calc

objective
rows is sorted by table_field_sum, already tried :
using 
orderby = table_field_sum inside select()
result
no error occured but the result not expected

using
for row in rows.sort(lambda row: table_field_sum) 
result
(no error occured but the result not expected)

question
how to achieve it in web2py ?
thx
Reply all
Reply to author
Forward
0 new messages