I have a table with name transaction (Model: Transaction). Here is my table structure:
Type | Quantity |
---|---|
+ | 10 |
- | 4 |
+ | 15 |
- | 15 |
Here I want sum of total quantity, where all the -
should be subtracted and all the +
should be added. How can I get ?
I have added all +
(this is purchase) and subtracted -
(this is sale) with 2 different queries this way:
Transation::sum('Quantity')->where('Type','+') - Transation::sum('Quantity')->where('Type','-')
.
Is there any better and single query than multiple queries ?