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 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 current price by the most recent sales figure > price_sales = price_table.price / fundamental_table.sales where > fundamental_table.reportdate<=price_table.date order by > fundamental_table.reportdate limit 1 > > I would also like this price_sales to be an attribute that is itself > queryable, eg, so I can express > > select all where ratio_data.price_sales<2 and and price_data.price>5 > > I am a bit of a sqlalchemy newbie -- I have written the price data and > fundamental tables below. If there is a way to express the above > ratio data as a handy sqlalchemy map, I'd appreciate any suggestions if the attribute is "attached" to either PriceData or FundamentalData, the general route towards this kind of thing is to use column_property(). You can place subqueries which correlate to the base table in those. If you're looking for a third mapped object along the lines of RatioData, you can map such a class to a select() object which represents the query, although this seems more like an attribute on PriceData. the column_property() is usable in queries and you can also customize how it compares using a user-defined PropComparator. a brief example is at: http://www.sqlalchemy.org/docs/05/mappers.html#advdatamapping_mapper_expressions --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---