2017-01-01 75 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