On Wed, 2006-07-19 at 14:50 +0200, Maciej Bliziński wrote: [...] > ------------------------------------------------------------------- > SELECT > dt.name, > count(*) > FROM > myapp_tag AS st -- source tag > INNER JOIN myapp_document_tags AS sti ON (st.id = sti.tag_id) > INNER JOIN myapp_document AS d ON (sti.document_id = d.id) > INNER JOIN myapp_document_tags AS dti ON (d.id = dti.document_id) > INNER JOIN myapp_tag AS dt ON (dti.tag_id = dt.id) > WHERE > st.name = 'tag1' -- define the source tag > AND > st.id <> dt.id -- list only other tags > GROUP BY > dt.name > ORDER BY > count(*) DESC > ; > ------------------------------------------------------------------- > > Example result: > > name | count > ------+------- > tag5 | 6 > tag2 | 6 > tag8 | 6 > tag3 | 4 > tag7 | 4 > tag6 | 4 > tag0 | 3 > tag4 | 2 > (8 rows) > > Shows, that tag5, tag2 and tag8 are associated with the same documents > as tag1 in 6 cases. And so on. > > The question is: > is it possible to make the same thing without writing custom SQL code?
Basically, no, because there is no way at the moment to do the equivalent of an SQL "group" command. One day, this sort of thing should be possible, but not right now. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---