Calculate aggregations?
I want to
sum_1 = sum_some_data(user_1, :column_1)
, sum_2 = sum_some_data(user_1, :column_2)
then sum_1 - sum_2
and return this value.9 Replies
Can you provide a concrete example of the kind of data this might be?
like for each user, its the sum of some related value?
sum_one_on_one(user_1, :user_1_id) - sum_one_on_one(user_1, :user_2_id)
So
sum_one_on_one
in this case, would do something like be the count of users that a person is connected to?It is summing how many
one_on_one
where they were :user_1_id
and subtracting that from the sum of one_on_one
where they were :user_2_id
šŖ :magic_sparkles:
AHHH
expr(count_of_user_1_one_on_ones - count_of_user_2_one_on_ones)
Well it is the combination of the aggregates and calculation!Yep š
The equivalent "manual" calculation would look like this:
Then you could say
calculate :whatever_this_is_called, :integer, YourCalc
But, when you can use expr/1
, you should. Just showing how it might be done if you have something super custom you want to do.Ok, thanks! That is what I thought it would be! Phew. I think I am done. I'll share once I am done with this little project.
Have a good rest of your day/night Zach!
Thanks, you as well!