I get an error saying the countall doesn't appear in the groupby, or its not an aggregating function.
sqlalchemy.exc.ProgrammingError: (ProgrammingError) column "anon_2.countall" must appear in the GROUP BY clause or be used in an aggregate function session = SqlMapping().createSession() subq = session.query(func.count('*').label('countall')).select_from(ReportableCondition).subquery() qry = session.query(ReportableCondition.disease, func.count(1).label('number'), ((100*func.count(1)) / subq.c.countall)).group_by(ReportableCondition.disease) for result in qry: print result On Aug 29, 5:04 pm, Mike Conley <mconl...@gmail.com> wrote: > 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 <lhfied...@gmail.com> 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 sqlalchemy@googlegroups.com. > > To unsubscribe from this group, send email to > > sqlalchemy+unsubscr...@googlegroups.com. > > 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 sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.