On Mon, Nov 10, 2008 at 8:53 AM, King Simon-NFHD78
<[EMAIL PROTECTED]> wrote:
> It should be fairly easy to build that query with SA's underlying
> expression language. I'm not certain how to do it through session.query,
> but I'm sure it's possible.
The snippet you posted does do what I want when inserted directly into
mysql database. I am getting close on the sqlalchemy incantation::
In [106]: q = session.query(Snapshot.strategy, Snapshot.symbol,
sum_pnl).group_by(Snapshot.strategy,
Snapshot.symbol).having(sum_pnl<-15000)
In [107]: newq = session.query(Snapshot.strategy, func.count('*'))
In [108]: print newq.select_from (q.subquery
()).group_by(Snapshot.strategy )
SELECT anon_1.strategy AS anon_1_strategy, count(%s) AS count_1
FROM (SELECT snapshot.strategy AS strategy, snapshot.symbol AS
symbol, sum(snapshot.pnl) AS sum_1
FROM snapshot GROUP BY snapshot.strategy, snapshot.symbol
HAVING sum(snapshot.pnl) < %s) AS anon_1 GROUP BY snapshot.strategy
The main problem is that the last "GROUP BY snapshot.strategy" is not
what I want, since I need to be doing "GROUP BY anon_1.strategy". Is
there some label magic I can employ to explicitly refer to the
Snapshot.query from the original "q" rather than the one from "newq"?
Thanks,
JDH
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---