been working all day long on this, and i don't feel like i've gotten
any closer than when i started..  read all the related posts on this
group and couldn't determine what to do based on those.  hoping
someone can shed some light.

i'm attempting to convert the codebase of an existing project i've
developed to use SA.  going ok so far, but i'm stuck on an important
query that contains a subquery and that subquery has a count
function.  the original query looks like this:

    SELECT id, name, count
    FROM (
        SELECT t.id, t.name, COUNT(*) AS count
        FROM tags t, object_tags ot
        WHERE t.id= ot.tag_id
        AND ot.object_type_id = 2
        GROUP BY t.id, t.name
        ORDER BY COUNT(*) DESC, t.name ASC
        LIMIT 35
    ) AS t
    ORDER BY name ASC

tho actually, i will be changing the LIMIT clause and the final ORDER
BY clause depending on what the user chooses.  this is a query whose
results are used to render a tag cloud..  i've got an intermediate
table called 'object_types' that has a lookup of different types of
entities that could be tagged.  e.g. articles or users.  so articles
has the object_type_id 2 in the above sql, and that's what i'm
generating the cloud for.  object_tags is the relation table that maps
tags and object types to objects..

i had to do the query this way so that i can first get the top [limit]
number of tags ordered by count and name, and then being able to order
that top tag result set further.  basically i'm just saying that i
don't see a way to do this without the subselect..

so, how would i go about doing this??  it seems like i need to use
session.query(Tag) with from_statement, func and add_column, but i
just can't figure it out.  i'm seriously just about to pull my hair
out trying to understand what to do. any help is greatly appreciated!

- m@

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to