What I need is only a list of the items in "Storage", but the resulting set should include the sum of that item's quantity in both the storage and active locations.
Here's a dataset example:
| ID | Item | Location | Qty |
|---|---|---|---|
| 1 | ItemA | Storage | 4 |
| 2 | ItemA | Active | 9 |
| 3 | ItemB | Storage | 3 |
| 4 | ItemB | Storage | 2 |
| 5 | ItemA | Active | 1 |
| 6 | ItemC | Boxed | 3 |
| 7 | ItemD | Active | 1 |
| 8 | ItemD | Storage | 1 |
The result would look like this:
| Item | Storage | Active |
|---|---|---|
| ItemA | 4 | 10 |
| ItemB | 5 | 0 |
| ItemD | 1 | 1 |
Note that ItemC should not be included because it is not in a valid location.
What I have tried so far is:
SELECT
ITEMDESC.A,
SUM(CASE WHEN LOCATION.A='Storage' THEN QTY.A ELSE 0 END),
SUM(CASE WHEN LOCATION.B='Active' THEN QTY.B ELSE 0 END)
FROM
ITEMS A, ITEMS B
INNER JOIN
ITEMDESC.A = ITEMDESC.B
WHERE
GROUP BY
ITEMDESC.A
but this returns ALL items listed. When I add something like "WHERE Location.B = 'Storage'" then it only sums the items in the storage and all the active location items are 0.