Skip to content
Advertisement

How to get sum of specific status or id and joining 3 table in laravel

my table

this is the result I want to display john — total paid shoes and bag dave <– total of bag,’shoes is unpaid so 1000 is not added to total’

this is my controller it gives me an error the total is same in all name

Advertisement

Answer

You could look to join sub queries, that certainly would be one approach. Here is an example:

The first subquery would give the total sales amount based on type from table1 achieved by grouping table2_id and using a sum operation on the amount. So the result would list user_id/table2_id and the amount per type.

The second subquery would give the total sales for individual customers/user by joining the first subquery. Group by cutomer/user/table1_id to get a sum on the amount from the first query to get the total for a individual customers.

Join the second to the users table and you should have the desired result.

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