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). Sample 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;
How do I create the above query using SqlAlchemy select & join functions?