rows = db(query).select(db.cart_sharing.created_by.with_alias('sharer'),
db.cart_sharing.stats.count().with_alias('carts'),
db.cart_sharing.stats.sum().with_alias('shares'),
groupby=db.cart_sharing.created_by,
orderby=['~shares'])
Try [~db.cart_sharing.stats.sum()]
--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/87RAPjGI0_k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/026bdb99-f659-4d35-849c-3df119671f9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
orderby='shares DESC'
Anthony, it works like a charm, thank you very much!!(Val's solution with also worked great, but it felt awkward to use the whole thing when an alias was created, so emotionally this solution with alias feels better :)
sum = db.cart_sharing.stats.sum()
On a side note, for SQLite orderby=['~shares'] works perfect - it indeed sorts it out properly. Just in case I've verified it again now.
By the way, Val's solution was orderby=[~db.cart_sharing.stats.count()] - with tilda, and it worked even in Postgres. Somehow tilda doesn't work specifically with an alias - but without an alias it's just fine on both dbs.
SUM("cart_sharing"."stats") DESC
But in any case, orderby=['shares DESC'] works everywhere flawlessly and feels good too, so it's a winner :)
--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/87RAPjGI0_k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/d89ca392-0d5f-4320-81b5-633ca95d51c2%40googlegroups.com.