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

Write a query to display each sales reps ID and the total number of customers th

ID: 3593789 • Letter: W

Question

Write a query to display each sales reps ID and the total number of customers that they have. Only include those reps that have more than 10 customers.

SalesRep PK RepID varchar(20) varchar(20) PK CustomerlD int LastName FirstName CommissionRatedecimal(10,2) LastName vrchar(20) FirstName varchar(20) Street varchar(20) varchar(20) char(2) Zipcode chr(5) Balance decimal(10,2) -0 P OrderlD int FK1 ReplD FK1 CustomerlD int OrderDat date ShipDate date Part PK PartID Description varchar(20) UnitsOnHand int ItemClass PK,FK1 OrderlDint PK,FK2 PartIDint decimal (10,2) decimal(10,2) Quantityint

Explanation / Answer

We can retrive the above query by using join and also by using aliases. Here I have posted two queries. Please do observe.

using alias:

select s.sale_rep_id, count(c.customerid)from sales_rep s,customer c groupby s.sale_rep_id having count(c.customerid)>10;

Using Join:
SELECT RepID, COUNT(CustomerID) AS ‘Total Customer’ FROM SalesRep INNER JOIN Customer USING(RepID)GROUP BY RepID HAVING COUNT(CustomerID) > 10;

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