Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8890831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:35:33+00:00 2026-06-14T22:35:33+00:00

Im trying to figure out what this code is going: SELECT EMP_ID, SUM(INV_PRICE) AS

  • 0

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:

enter image description here

Here is what I get when I run > average:

enter image description here

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:35:34+00:00Added an answer on June 14, 2026 at 10:35 pm

    No, it’s not. The SUM(INV_PRICE) will give you the total sales of an employee but the AVG(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:

    SELECT EMP_ID, SUM(INV_PRICE) AS TOTAL_SALES
    FROM INVOICE
    GROUP BY EMP_ID
    HAVING SUM(INV_PRICE) <= 
             ( SELECT SUM(INV_PRICE) FROM INVOICE )
           / ( SELECT COUNT(*) FROM EMPLOYEE )
      ; 
    

    or this if you want the average of all employees that have sales:

    SELECT EMP_ID, SUM(INV_PRICE) AS TOTAL_SALES
    FROM INVOICE
    GROUP BY EMP_ID
    HAVING SUM(INV_PRICE) <= 
             ( SELECT SUM(INV_PRICE) / COUNT(DISTINCT EMP_ID) 
               FROM INVOICE )
      ; 
    

    Skip that, Access has no COUNT(DISTINCT ):

    SELECT EMP_ID, SUM(INV_PRICE) AS TOTAL_SALES
    FROM INVOICE
    GROUP BY EMP_ID
    HAVING SUM(INV_PRICE) <=
             ( SELECT AVG(TOTAL_SALES)
               FROM
                 ( SELECT SUM(INV_PRICE) AS TOTAL_SALES
                   FROM INVOICE
                   GROUP BY EMP_ID 
                 ) tmp
             ) ; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to figure out this pseudo code. The following is assumed.... I can only
I'm trying to figure out why this code won't compile. I have interface A
I'm trying to code this site (keyword trying) and I'm trying to figure out
I am trying to figure out how to simplify this piece of code. The
I am trying to figure out why I get this error. My code is
I'm trying to figure out this weird issue I've been having, and the root
I am trying to figure out this error from previous 3 hours. By searching,
I am going nuts trying to figure this out, I am trying to build
I've been trying to figure out why this code is not getting hit. The
I am going crazy trying to figure this out without success. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.