2013-10-12 105 views
1

我有愚蠢的問題執行查詢。由於我在goals_num變量中存儲整數,因此我打算將它用於另一個查詢,但它不會運行任何操作。然而,如果不是goals_num我插入221(這是它包含的內容)查詢運行我得到結果打印。任何人都可以告訴我有什麼問題嗎?謝謝!sqlite3和紅寶石查詢執行

puts goals_num = db.execute("select MAX(goals) from EnglandTopScorers") 

db.execute("select * from EnglandTopScorers where goals='#{goals_num}' ") do |row| 
    puts row 
end 

回答

0

我覺得問題是db.execute的返回值。如果我記得這將返回一個數組。因此goals_num是一個數組。要檢索該值,您可能需要將其更改爲:

goals_num = db.execute("select MAX(goals) from EnglandTopScorers").first 
db.execute("select * from EnglandTopScorers where goals='#{goals_num}' ") do |row| 
    puts row 
end