[sqlalchemy] Re: select where field=max(field)

2008-11-11 Thread John Hunter
On Tue, Nov 11, 2008 at 4:31 AM, King Simon-NFHD78 [EMAIL PROTECTED] wrote: Which is pretty much the query we wanted, apart from the names. I hope it works in your original example as well! This worked great -- and I learned a bunch of useful sql and sqlalchemy tricks along the way. Many

[sqlalchemy] Re: select where field=max(field)

2008-11-10 Thread John Hunter
On Mon, Nov 10, 2008 at 4:33 AM, King Simon-NFHD78 [EMAIL PROTECTED] wrote: I'm no SQL expert, so please take this with a pinch of salt, but as far as I know, conditions in the 'WHERE' clause of an SQL statement are applied BEFORE any grouping, so you can't use grouping functions (such as

[sqlalchemy] Re: select where field=max(field)

2008-11-10 Thread John Hunter
On Mon, Nov 10, 2008 at 10:05 AM, King Simon-NFHD78 [EMAIL PROTECTED] wrote: Actually, the section after that (Using Subqueries) probably does something very close to what you want. What's the result of these lines: q1 = (session.query(Snapshot.strategy, Snapshot.symbol, sum_pnl)

[sqlalchemy] Re: select where field=max(field)

2008-11-10 Thread John Hunter
On Mon, Nov 10, 2008 at 11:10 AM, Michael Bayer [EMAIL PROTECTED] wrote: you need an extra tuple on the join, query.join((q1, s.s==q1.c.s)) This gets past the syntax error, but does not produce the right results. I had to take some time off today to work on other problems, but am now

[sqlalchemy] select where field=max(field)

2008-11-07 Thread John Hunter
I am having trouble writing a sqlalchemy query which selects all rows where a field equals the max for that field, eg q = session.query(Snapshot).filter(Snapshot.totalqty==func.max(Snapshot.totalqty)) When I try and get the results of the query, I get the error below. How should I use

[sqlalchemy] Re: select where field=max(field)

2008-11-07 Thread John Hunter
On Fri, Nov 7, 2008 at 3:57 PM, Michael Bayer [EMAIL PROTECTED] wrote: Theres a good tutorial on the topic of GROUP BY from a SQL perspective, here: http://weblogs.sqlteam.com/jeffs/jeffs/archive/2007/07/20/60261.aspx in this case you probably want

[sqlalchemy] ratio on multiple tables

2008-10-09 Thread John Hunter
I have some tables with financial data -- one table has price data on a given date and another data has fundamental data on a given report date. I am wondering if it is possible to create another object that is a ratio on a join between values in the two tables, eg in pseudo code # divide the

[sqlalchemy] Re: ratio on multiple tables

2008-10-09 Thread John Hunter
On Thu, Oct 9, 2008 at 6:28 PM, Michael Bayer [EMAIL PROTECTED] wrote: On Oct 9, 2008, at 3:28 PM, John Hunter wrote: I have some tables with financial data -- one table has price data on a given date and another data has fundamental data on a given report date. I am wondering