This should work

    subq = sess.query(func.count('*').label('countall')).\
        select_from(FilmParticipation).subquery()

    qry = sess.query(FilmParticipation.PartType,
                func.count(1).label('Amount'),
                ((100*func.count(1)) / subq.c.countall)).\
                group_by(FilmParticipation.PartType)

-- 
Mike Conley



On Mon, Aug 29, 2011 at 3:05 PM, nospam <[email protected]> wrote:

> I'm trying to construct a query in sqlalchemy similiar to this:
> SELECT FilmParticipation.PartType, COUNT(*) AS Amount,
>  100*COUNT(*) /(SELECT count(*) FROM FilmParticipation) AS
> Percentage_of_Total
>  FROM FilmParticipation
>  GROUP BY FilmParticipation.PartType;
>
> I create a subquery for the nested select, but, I get a
> NoSuchColmnError on the percentage part.
>
> Any ideas how this could be constructed?
>
> Cheers,
>  Lars
>
> --
> 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.
>
>

-- 
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.

Reply via email to