Generated on Jan 15, 2025, 11:32:41 AMgemini-1.5-flash
-- SQL Server query to retrieve staff information and their total quantity of items sold.
-- Selects the staff's first name, last name, email, and calculates the sum of quantities sold for each staff member.
SELECT
staffs.first_name AS 'First Name', -- Staff's first name.
staffs.last_name AS 'Surname', -- Staff's last name.
staffs.email AS 'Email', -- Staff's email address.
SUM(order_items.quantity) AS [Total quantity sold] -- Total quantity of items sold by the staff member.
FROM
BikeStores..orders -- Joins the 'orders' table...
JOIN
BikeStores..order_items ON orders.order_id = order_items.order_id -- ...to the 'order_items' table using the order ID.
JOIN
BikeStores..staffs ON orders.staff_id = staffs.staff_id -- ...and to the 'staffs' table using the staff ID.
GROUP BY
staffs.first_name, -- Groups the results by staff's first name...
staffs.last_name, -- ...last name...
staffs.email -- ...and email address to aggregate sales per staff member.
ORDER BY
[Total quantity sold] -- Orders the results in ascending order based on the total quantity sold.