Query System Requirements for a software project:
Data Tables:
Name Quantity Status ----------------------- Product A 10 purchases Product A 20 sales Product B 20 purchases
The query result is:
Product Name inventory quantity ----------------------- Product A-10 Product B 20 |
Solution 1:
Select
Distinct name,
(Isnull (select sum (A. Quantity) from the Database Table A where a. Name = database table. Name and A. Status = 'retain'), 0)
-
Isnull (select sum (A. Quantity) from inventory table A where a. Name = inventory table. Name and A. Status = 'sales'), 0) as inventory quantity
From
Inventory table
Solution 2 (ACCESS ):
Select name, sum (IIF (status = 'purchase ', 1,-1) * quantity) as inventory quantity from database table group by name
Solution 3 ):
select name, sum (IIF (status = 'retain', quantity, 0)-IIF (status = 'sold out', quantity, 0 )) as inventory quantity from database table group by name