我如何查询返回的列

时间:2012-02-25 21:03:39

标签: ruby activerecord

我在ruby中创建了这个脚本来计算mfe mae。但它返回一个活动记录,我无法查询其列。 如果我做了puts["mini"]我得到了

D:/TradingTools/torontotrader/app/helpers/rb1A5.tmp:28:in '[]': can't convert String into Integer (TypeError)
    from D:/TradingTools/torontotrader/app/helpers/rb1A5.tmp:28
    from D:/TradingTools/torontotrader/app/helpers/rb1A5.tmp:24:in `each'
    from D:/TradingTools/torontotrader/app/helpers/rb1A5.tmp:24
Complete(1)

我输出了详细信息,它是TickData类型,我返回的columsn是聚合类型。我怎样才能获得价值

class TickData < ActiveRecord::Base
  set_table_name "tickdata" 
end
class Trades < ActiveRecord::Base
  set_table_name "trades" 
end
class TradesReport < ActiveRecord::Base
  set_table_name "tradesreport" 
end

sql="select * from tradesreport where entry>=(select  min(time)  from tickdata ) and exitt <=(select  max(time)  from tickdata )"

tradestocalculate= Trades.find_by_sql(sql) 
tradestocalculate.each {|item|
  sql="select MIN(LASTPRICE) as mini,MAX(LASTPRICE) as  maxi,COUNT(*) as no from tickdata where time >='#{item['entry']}' AND time <= '#{item['exitt']}' and 
symbol like '%#{item['symbol_alias'][0,3]}%'"
  details= TickData.find_by_sql(sql)
  puts  details["mini"]

1 个答案:

答案 0 :(得分:2)

您的结果位于details[0]['mini']details[0]['maxi']details[0]['no']