Chapter Two – Introduction to Structured Query Language
Page 2-31
Unfortunately, Microsoft Access cannot process the ORDER BY clause because it contains an
aliased computed result. To correct this, we use an SQL statement with the un-aliased
computation:
SELECT WarehouseID, SUM(QuantityOnHand) AS TotalItemsOnHand
FROM INVENTORY
GROUP BY WarehouseID
ORDER BY SUM(QuantityOnHand) DESC;
The results, presented below in Access, are identical in all 4 DBMSs:
2.37 Write an SQL statement to display the WarehouseID and the sum of QuantityOnHand
grouped by WarehouseID. Omit all SKU items that have three or more items on hand
from the sum, name the sum TotalItemsOnHandLT3, and display the results in
descending order of TotalItemsOnHandLT3.
SELECT WarehouseID, SUM(QuantityOnHand) AS TotalItemsOnHandLT3
FROM INVENTORY
WHERE QuantityOnHand < 3