Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In SQL, create the query based on the model below: Retrieve the count of the mat

ID: 3874211 • Letter: I

Question

In SQL, create the query based on the model below:

Retrieve the count of the materials with supply unit price less than 5 supplied by each vendor. Output the vendor name and the count of materials supplied that meets this supply unit price criterion. Sort in descending order of materials supplied.

FIGURE 2-22 Data model for Pine Valley Furniture Company in Microsoft Visio notation SALESPERSON TERRITOR SIN PK Salesperson ID Serves PK Territory ID Salesperson Name Salesperson Telephone Salesperson Fax Territory Name CUSTOMER PRODUCT LINE PK Customer ID PK Product Line ID Customer Name Customer Address Customer Postal Code Product Line Name Submits Includes ORDER PK Order ID Order Date DUC ORDER LINE PK Product ID Product Description Product Finish Product Standard Price Ordered Quantity VENDOR USES PRODUCED IN PK Vendor ID Vendor Name Vendor Address Goes Into Quantity RAW MATERIAL WORK CENTER PK Material ID PK Work Center ID Material Name Material Standard Cost Unit Of Measure Work Center Location Supply Unit Price ls Supervised By EMPLOYEE WORKS IN SupervisesPEmployee ID HAS SKILL SKILL Employee Name Employee Address PK Skill

Explanation / Answer

The tables which will be used are Raw Material, Supply Unit Price and Vendor.
With the first join between Raw Material and Suppy Unit Price tables, we are finding the materials with supply unit less then 5. In the next join with vendor, we are finding the corresponding vendors.

Putting the count on material groupby vendor name.

Now the descending order cannot be applied on count function, hence this has been made as a subquery. And the outer query applies the descending order.


Select [Vendor Name], [Material Count]
from
(
Select VN.[Vendor Name], Count(RW.[Material ID]) [MATERIAL COUNT]
FROM [RAW MATERIAL] RW
INNER JOIN
[SUPPLY UNIT PRICE] SU
ON RW.[Material ID] = SU.[Material ID]
AND SU.[SUPPLY UNIT PRICE] < 5
INNER JOIN
VENDOR VN
ON VN.[VENDOR ID] = SU.[VENDOR ID]
GROUP BY VN.[VENDOR NAME]
) ORDER BY [Material Count] desc

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote