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) QuantityintExplanation / 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;
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.