Answer the question
In order to leave comments, you need to log in
How to make sum count of data from specific field in table (not DB) rails?
Hello, you need to calculate the sum of all "doctors' salaries from the table."
This is how I get the data
<% @doctor.each do |doc| %>
<tr>
<td><%= doc.doctor_first_name %></td>
<td><%= doc.doctor_second_name %></td>
<td><%= doc.current_money %></td>
<td><%= link_to 'Переглянути', doc %></td>
</tr>
<% end %>
def current_money
doctor_hour_price.to_f*users.where("enter_date >= ?", 7.days.ago).count
end
Answer the question
In order to leave comments, you need to log in
I think the calculation of the sum of all the money earned by doctors in a week is done like this:
Doctor.
joins(:users).
group("users.id").
where("enter_date >= ?", 7.days.ago).
select("SUM(COUNT(users.id) * doctor_hour_price) as total_money").
total_money
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question