Im trying to figure out what this code is going:
SELECT EMP_ID, SUM(INV_PRICE) AS TOTAL_SALES
FROM INVOICE
GROUP BY EMP_ID
HAVING SUM(INV_PRICE) <= AVG(INV_PRICE);
I wrote it or it was recommend to be a while a ago and now im not sure if its doing what I originally wanted it to do.
What I wanted: I have an invoice table with price and employees. I wanted to get each employees total sales and compare that to the average total sales for all employees. From there I wanted the results to show me which employees were selling below average.
Is what I have above correct?
Here is what I get when I run <= average:

Here is what I get when I run > average:

I think my main concern is making sure that it’s calculating the right average. Which is the average of the sum from each employee.
No, it’s not. The
SUM(INV_PRICE)will give you the total sales of an employee but theAVG(INV_PRICE)will give you the average sale per employee, not the average (for all employees) of their total sales.Try this of you want the average of total sales calculated for all employees – even those that have no sales at all:
or this if you want the average of all employees that have sales:
Skip that, Access has no
COUNT(DISTINCT ):