Find products that satisfy BOTH conditions below:______
(a) Its unit price must NOT below $22.
(b) Its category ID is 4 or 7 or 8. If its category ID is 1 or 3, then it must have at least 40 units in stock.
Display their Product ID, Unit Price, Category ID, and Units In Stock. The output should be sorted by Category ID in A -> Z order (i.e., from smallest to largest). For those with the same Category ID, the one with the highest Unit Price should be displayed first.
Hint 1: a compound condition with AND, OR, NOT.
Hint 2: correct output has 16 products.

Respuesta :

Answer:

Explanation:

--> First constraint should be satisfied.

UnitPrice>=22.

--> In Second and third either of one should be satisfied.

CategoryID in (4,7,8) OR (CategoryID in (1,3) AND UnitsInStock >= 40)

--> So, Final statement is :

SELECT ProductID, UnitPrice, CategoryID, UnitsInStock FROM Products

WHERE UnitPrice>=22 AND (CategoryID in (4,7,8) OR (CategoryID in (1,3) AND UnitsInStock >= 40))