Search code examples
mysqlsqlsql-serverrdbms

SQL Query - to check total amount of each employee and display those employee with amount less than 5000


I am currently doing a task where i need to calculate the sum of total amount of product each employee has. Then, I need to set a fix amount(5000) and display those employees who have total amount less than the fix amount(5000). Can anyone provide examples of queries for this particular problem?


Solution

  • Table T2 will return list of employees less than 5000,then join it with your employee master table T2. Change the table names as needed.

     SELECT * FROM EMPLOYEE T1 JOIN
     (SELECT EmployeeID,SUM(AMOUNT) AMOUNT FROM PRODUCT
     GROUP BY EmployeeID
     HAVING SUM(AMOUNT)<5000) T2 ON T1.EmployeeID=T2.EmployeeID