Link to home
Start Free TrialLog in
Avatar of phil301
phil301

asked on

SQL Grouping with Zero Value

I am attempting to sum up the number of parts on hand for given groups in the OrgTble column. The query below is working correctly, but it is not showing groups that have zero items in stock.

I would like for it to show something similar to the table below (It would not currently show the Shelf C 0).

Shelf A   5
Shelf B 10
Shelf C 0

How can I get the query below to show groups that do not currently have items in stock?

SELECT OrgTable, SUM(QtyOnHand) AS Quantity FROM All_Assets WHERE
(PartNumber = '015533913') GROUP BY OrgTable
Avatar of Rajkumar Gs
Rajkumar Gs
Flag of India image

Are you sure 'Shelf C' is in 'All_Assets ' table for PartNumber = '015533913' ?
Avatar of phil301
phil301

ASKER

Yes, this is a table with shelf locations of parts. If I enter a part number, I want it to return me all of the shelf locations and the number of parts in that location.
When we use GROUP BY OrgTable , the query should show distinct OrgTable data, if present in that table.
If the first column 'OrgTable' has some master table, then you can use JOIN and make this work
Avatar of phil301

ASKER

Currently, if there is zero parts in the shelf location, it just does not display the shelf location.
ASKER CERTIFIED SOLUTION
Avatar of reb73
reb73
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of phil301

ASKER

All of the data is present in the All_Assets table
What is the master table for 'Shelf A', 'Shelf B', ... data - I mean the column 'OrgTable' refers to which master table ?
Avatar of phil301

ASKER

Thanks reb, thats got it. It does pose another problem with selecting everything though.