This advanced SQL exercise is part of the book: Advanced SQL – Practical Techniques and Use-Cases, which includes 100 day-to-day SQL challenges (and solutions), need-to-know advanced features, and key concepts.
A store that sells M&M’S products manages two major tables.
The first table specifies the various products and their number in the inventory:
CREATE TABLE products_stock (productID int identity(1,1), productName varchar(150), unitsInStock int ) GO
The second table specifies the sales of these products:
CREATE TABLE products_sales (saleID int identity(1,1), productID int, unitsSold int, customerID int )