簡體   English   中英

在Rails中組合兩個SQL where語句

[英]Combing two SQL where statements in Rails

如何使這兩個WHERE語句都滿意?

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)

我嘗試了幾種方法,但無法正常工作。

謝謝

您可以使用多個問號:

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM