zsfhaergta
Programmer
Hi, I'm not quite a sql expert, and have been having some trouble figuring this out:
I have one table with ID, Side=1 or 2, and Qty. I'd like to group by ID where sum(Qty) where Side=1 - sum(Qty) where Side=2.
So basically the difference of all Qty's having side=1 minus all Qty's having side=2.
Table:
+--------+------+------+
| ID | Side | Qty |
+--------+------+------+
| 217938 | 1 | 100 |
| 217938 | 1 | 300 |
| 217938 | 1 | 250 |
| 217938 | 2 | 275 |
| 217938 | 2 | 120 |
| 217938 | 2 | 30 |
| 217939 | 2 | 125 |
+--------+------+------+
Result:
ID Difference
217938 225
217939 -125
Anyone able to figure this out? Thanks
I have one table with ID, Side=1 or 2, and Qty. I'd like to group by ID where sum(Qty) where Side=1 - sum(Qty) where Side=2.
So basically the difference of all Qty's having side=1 minus all Qty's having side=2.
Table:
+--------+------+------+
| ID | Side | Qty |
+--------+------+------+
| 217938 | 1 | 100 |
| 217938 | 1 | 300 |
| 217938 | 1 | 250 |
| 217938 | 2 | 275 |
| 217938 | 2 | 120 |
| 217938 | 2 | 30 |
| 217939 | 2 | 125 |
+--------+------+------+
Result:
ID Difference
217938 225
217939 -125
Anyone able to figure this out? Thanks