> i'm creating an event database, where i have events and users with a
> many-to-many relationship (think visitors). Now i want to get the most
> popular Events i.e. those with the most visitors.
Ok, my solution for now:
def popular(self):
limit = 10
ids = Event._connection.queryAll("SELECT e.id as id,
COUNT(rel.event_id) as count FROM event as e LEFT JOIN event_use\r as
rel ON e.id = rel.event_id GROUP BY e.id ORDER BY count DESC LIMIT %s" %
limit)
popular = list()
for id, count in ids:
popular.append(Event.get(id))
return dict(events=popular, title="popular")
The dict return value is for Turbogears ...
If you notice the difference of this SQL Statement to the post before.
This one gets entries with count = 0 as well.
have fun
Andi
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss