You supplied the join() as a the whereclouse (2nd) parameter to the
select method.
This should work:
select([tags_table.c.name,tags_table.c.id, func.count
(deal_tags_table.c.dealid).label('dealcount')],
from_obj=join(tags_table,
deal_tags_table),group_by=[deal_tags_table.c.dealid])
Regards
Bastian
On 4 Jun., 11:43, "[email protected]"
<[email protected]> wrote:
> I have two tables "tags" and "deal_tag", and table definition follows,
>
> Table('tags', metadata,
> Column('id', types.Integer(), Sequence('tag_uid_seq'),
> primary_key=True),
> Column('name', types.String()),
> )
>
> Table('deal_tag', metadata,
> Column('dealid', types.Integer(), ForeignKey('deals.id')),
> Column('tagid', types.Integer(), ForeignKey
> ('tags.id')),
> )
>
> I want to select tag id, tag name and deal count (number of deals per
> tag).
>
> I tried to create the query in sqlalchemy select function
>
> select([tags_table.c.name,tags_table.c.id, func.count
> (deal_tags_table.c.dealid).label('dealcount')],join(tags_table,
> deal_tags_table),group_by=[deal_tags_table.c.dealid])
>
> select function creates query linke this
>
> SELECT tags.name, tags.id, count(deal_tag.dealid) AS dealcount FROM
> tags JOIN deal_tag ON tags.id = deal_tag.tagid WHERE tags JOIN
> deal_tag ON tags.id = deal_tag.tagid GROUP BY deal_tag.dealid
>
> But my excepted query is
>
> SELECT tags.Name,tags.id,COUNT(deal_tag.dealid) FROM tags INNER JOIN
> deal_tag ON tags.id = deal_tag.tagid GROUP BY deal_tag.tagid;
>
> Please help me
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---