D
D
dk-web2016-03-25 17:41:18
Laravel
dk-web, 2016-03-25 17:41:18

Where to make calculations/calculations?

Others need advice.
There are two tables/models. In one, I store a list of orders, in the other, a list of counterparties and their commission.
1) orders
id| agent_id | item | cash
1 | 1 | - | 200
2 | 2 | - | 300
3 | 2 | - | 1000
2) agents
id | Commission
1 | 15
2 | 20
The amount of orders grouped by agents, excluding commission, I can get,
1 | 170
2 | 1040
but how to get the total amount of orders? (1210?)
Through request? in the model? controller? Repositories? something again just spawned ...
In other words, I need to get the total sum of the multiplication of two columns from different tables ...
UPD. something like... SELECT sum(a.cash*b.comission) FROM orders as a JOIN agents as b ON a.agent_id=b.id

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DuD, 2016-03-27
@DuD

All calculations that can be done with a query are best done with a query. The database will almost always make calculations faster.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question