Welcome Back

Google icon Sign in with Google
OR
I agree to abide by Pharmadaily Terms of Service and its Privacy Policy

Create Account

Google icon Sign up with Google
OR
By signing up, you agree to our Terms of Service and Privacy Policy
Instagram
youtube
Facebook

List Employees Who Processed More Than 2 Orders

List Employees Who Processed More Than 2 Orders

Employees Table:



Orders Table:


Query Explanation:
What this does:

  • JOIN: Combines both tables where the EmployeeID matches.

  • GROUP BY: Groups orders per employee.

  • COUNT(O.OrderID): Counts how many orders each employee processed.

  • HAVING COUNT(O.OrderID) > 2: Filters only those employees who processed more than 2 orders.

  • SELECT: Shows the ID, name, and total order count of those employees.


SQL Query:

SELECT 
    E.EmployeeID,
    E.FirstName,
    E.LastName,
    COUNT(O.OrderID) AS TotalOrders
FROM 
    Employees2 E
JOIN 
    Orders2 O ON E.EmployeeID = O.EmployeeID
GROUP BY 
    E.EmployeeID, E.FirstName, E.LastName
HAVING 
    COUNT(O.OrderID) > 2;


Output: