Skip to content
Advertisement

Larave conditional aggregation to get multiple sum of amount

Hope all is well.

Anyone can tell me how can I get to run this SQL query in a the right way in Laravel?

Controller:

JavaScript

I expect to use it in my view as follows:

JavaScript

I’m new to Laravel, I would appreciate your help. Thank you in advance.

Advertisement

Answer

I believe you want an agrregated query with conditional sum of amount for each user within a specific country. In pure SQL it can done using CASE statements as

JavaScript

In query builder it can be tranformed as

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement