I'm trying to find the average difference between the creation date and the last update of the records in a table as follows:
tickets = Ticket.all.where('updated_at IS NOT NULL')
t = tickets.sum(:updated_at, conditions: 'updated_at.to_time') - tickets.sum(:created_at, conditions: 'created_at.to_time')
But this is giving error, where am I wrong?
I did it this way below and it worked; but I believe that without doing this loop I would gain in performance.
tickets = current_client.tickets.where('updated_at IS NOT NULL')
t = 0
tickets.each do |ticket|
t += ticket.updated_at.to_time - ticket.created_at.to_time
end