Login

Tag "group-by"

Snippet List

Custom SQL via subquery

You can use custom SQL statements with the existing database API by creating a subquery specified via the `tables` parameter of `extra`. (This has only been tested with MySQL and may not work with all database back-ends.)

  • group-by
Read More

Fetching top items

This is a method from the custom manager for the Snippet model used on this site; the basic idea is to be able to ask for the top `n` "foo", where "foo" is something related to Snippet. For example, you can use `top_items('tag')` to get the top Tags ordered by how many Snippets are associated with them. I have a feeling that I could get this down to one query, but haven't yet put in the time for it.

  • snippets
  • sql
  • managers
  • group-by
Read More

2 snippets posted so far.