Thanks, it works with total_entries = db(db.test.id > 0).count() [next_to_last,last] = db().select(db.test.ALL, limitby=(total_entries-3, 2))
But crashes with more than 3 entries: ValueError: need more than 1 value to unpack However, it works this way (switched "3" with "total_entries"): [next_to_last,last] = db().select(db.kpi.ALL, limitby=(total_entries- *total_entries*, 2)) Question: Could this cause a problem (math or otherwise)? On Thursday, January 8, 2015 6:55:28 AM UTC+1, Kiran Subbaraman wrote: > > Am assuming you want the last two records in a table all the time, and > they correspond to the variables A, B. > If you know the number of records in that table, via the count method, or > a more efficient mechanism, then you can use the limitby statement to get > the last two records. > > total_records = #number of records in the test table - computed via > count, or some other method > [A,B] = db().select(db.test.ALL, limitby(total_records - 3, 2) > > ________________________________________ > Kiran Subbaramanhttp://subbaraman.wordpress.com/about/ > > On Thu, 08-01-2015 10:56 AM, Timo Bahner wrote: > > Hi guys. > > Let's assume the following table > > db.define_table('test', Field('letter', 'double')) > > How can I compare two 'letter' entries if for example > > A=1.23 > B=4.56 > > To get the last entry (B) I'll use > > last_entry = db().select(db.test.ALL).last() > > *But how do I get the entry before the last, in this case letter A?* The > actual comparing will be done within index.html to check if B is greater or > equal to A for example > > {{if B >= A:}} > <!-- some html code--> > {{else:}} > <!-- some html code--> > {{pass}} > > > > -- > Resources: > - http://web2py.com > - http://web2py.com/book (Documentation) > - http://github.com/web2py/web2py (Source code) > - https://code.google.com/p/web2py/issues/list (Report Issues) > --- > You received this message because you are subscribed to the Google Groups > "web2py-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] <javascript:>. > For more options, visit https://groups.google.com/d/optout. > > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.

