简体   繁体   中英

Ruby on Rails- Query Amount between two dates from console

I want to query total amount (which is a column in all the records) and have an option to choose dates to get the sum of the amount between those dates.

What is the best way to do that?

You can use sum :

Model.sum(:amount)

To select dates, just add where :

Model.where(date: from_date..to_date).sum(:amount)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM