The SQL Code below pull data in Fig. 1. I wantto pull the minimum OrderCount from eachCategoryName. Please write SQL Code for Fig. Thecode should give results in Fig 2. The minimum isderive from COUNT(O.OrderID) AS ‘OrderCount’.

Note: OrderCount is alias.

SQL Code:

——————————————————————

SELECT
C.CategoryName
,O.ShipVia
,COUNT(O.OrderID) AS ‘OrderCount’
FROM Orders O
   INNER JOIN Shippers S
       ON O.ShipVia = S.ShipperID
   INNER JOIN [Order Details] D
       ON O.OrderID = D.OrderID
   INNER JOIN Products P
       ON D.ProductID = P.ProductID
   INNER JOIN Categories C
       ON P.CategoryID =C.CategoryID
GROUP BY C.CategoryName, O.ShipVia
ORDER BY C.CategoryName, O.ShipVia

———————————————————————-

Results:

Fig. 1 CategoryName Shipia OrderCount Beverages Beverages 2 Beverages 3 Condiments 1 Condiments 2 Condiments 3 Confections 1 Confections 2 Confections 3 122 164 118 72 81 63 100 133 101 Fig. 2 CategoryName MinOrders Shipped Beverages 118 Condiments 63 Confections 100

Fig. 1 CategoryName Shipia OrderCount Beverages Beverages 2 Beverages 3 Condiments 1 Condiments 2 Condiments 3 Confections 1 Confections 2 Confections 3 122 164 118 72 81 63 100 133 101 Fig. 2 CategoryName MinOrders Shipped Beverages 118 Condiments 63 Confections 100 Show transcribed image text Fig. 1 CategoryName Shipia OrderCount Beverages Beverages 2 Beverages 3 Condiments 1 Condiments 2 Condiments 3 Confections 1 Confections 2 Confections 3 122 164 118 72 81 63 100 133 101 Fig. 2 CategoryName MinOrders Shipped Beverages 118 Condiments 63 Confections 100