ruby on rails - How to get records by month -


i have tried several solutions 1 close enough want this

sale.all.group("date_trunc('month', created_at)").count 

but returns this

{2016-07-01 00:00:00 utc=>19, 2016-04-01 00:00:00 utc=>70}

is there can format?

[month,number of sales] ??

using postgres db.

try use extract function of postgresql,

in rails code

results = sale.all.group("extract(month created_at").select("extract(month created_at) month, count(*) count")  p results[0].month if results[0] 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -