347,850 views
12 votes
12 votes
The Binder Prime Company wants to recognize the employee who sold the most of its products during a specified period. Write a query to display the employee number, employee first name, employee last name, email address, and total units sold for the employee who sold the most Binder Prime brand products between November 1, 2017, and December 5, 2017. If there is a tie for most units sold, sort the output by employee last name

User Tor Valamo
by
2.6k points

2 Answers

22 votes
22 votes

Final answer:

To find the employee who sold the most Binder Prime products between specific dates, use a SQL query that joins the employees, sales, and products tables, filters the results by brand and date range, calculates the total units sold by each employee, groups the results, and sorts them.

Step-by-step explanation:

To display the employee who sold the most Binder Prime brand products between November 1, 2017, and December 5, 2017, you can use the following SQL query:

SELECT employee_number, first_name, last_name, email, SUM(units_sold) as total_units_sold
FROM employees
JOIN sales ON employees.employee_number = sales.employee_number
JOIN products ON sales.product_id = products.product_id
WHERE brand = 'Binder Prime' AND sale_date BETWEEN '2017-11-01' AND '2017-12-05'
GROUP BY employee_number, first_name, last_name, email
ORDER BY total_units_sold DESC, last_name ASC
LIMIT 1;

This query joins the employees, sales, and products tables and filters the results based on the brand 'Binder Prime' and the specified date range. It calculates the total units sold by each employee, groups the results by employee, and then sorts the output in descending order by total units sold and ascending order by last name. Finally, it limits the output to the top employee.

User Eran Abir
by
3.1k points
10 votes
10 votes
The answer will be one month
User Zxcmehran
by
3.3k points