2017-01-01 73 views
0

请问如何使这两条WHERE语句满意?在Rails中梳理两条SQL语句

where("cast(strftime('%d', date) as int) = ?", month) 
where("cast(strftime('%Y', date) as int) = ?", year) 

喜欢的东西:

where("cast(strftime('%d', date) as int) = ?", month) AND 
     where("cast(strftime('%Y', date) as int) = ?", year) 

我已经尝试了一些方法,但不能得到它的工作。

感谢

回答

1

您可以使用多个问号:

where("cast(strftime('%d', date) as int) = ? 
     AND cast(strftime('%Y', date) as int) = ?", month, year) 

或者只是使用2点where声明:

where("cast(strftime('%d', date) as int) = ?", month) 
.where("cast(strftime('%Y', date) as int) = ?", year) 
+0

谢谢,非常完美。 – Simonp27

+0

@ Simonp27欢迎您 – Ilya