query_report icon indicating copy to clipboard operation
query_report copied to clipboard

Apply where condition

Open catmal opened this issue 9 years ago • 0 comments

Let say I have a table with column AMOUNT and TYPE. Amounts 10,20,50. Type 1,1,2

Let say I want in a column the sum of amounts for which type is 1. Result should be 30. And in another column sum of amounts for which type is 2. Result should be 50.

In controller I can apply sum in this way sum(AMOUNT) as total_amount and then call column :total_amount.

But I am unable to apply the condition where type = 1.

I understand that it can't be done through a scope or new method as column refers to db tables not active records.

Is this possible at all?

catmal avatar Sep 27 '16 07:09 catmal