Okay guys here is the question. I have to list the department ID, department name, count of sales reps, and average commission rate for each department. Also I need to Group by
SELECT DE.Dept_ID as Dept_ID,
Dept_Name,
COUNT(SR.Sales_Rep_ID) as NumOfSalesR,
AVG(Comm_Rate) as AVGCOM
FROM DEPT_arb DE, SALES_REP_arb SR, COMMISSION_arb C
WHERE DE.Dept_ID = SR.Dept_ID
GROUP BY E.Dept_ID,
Dept_Name,
ORDER BY C.Comm_Rate;
You may also consider properly joining the tables, for i.e.:
SELECT DE.Dept_ID as Dept_ID,
Dept_Name,
COUNT(SR.Sales_Rep_ID) as NumOfSalesR,
AVG(Comm_Rate) as AVGCOM
FROM DEPT_arb DE
JOIN SALES_REP_arb SR on DE.Dept_ID = SR.Dept_Id
JOIN COMMISION_arb C on SR.Comm_Class = C.Comm_Class
GROUP BY E.Dept_ID,
Dept_Name,
ORDER BY C.Comm_Rate;