Reputation: 89
In my Access database I have a three different tables based on a pizza company:
What query can I write to show the names of all the delivery staff and the number of items they have delivered? I understand I have to use table aliases but as I am new to SQL I am having problems finding a solution.
Upvotes: 0
Views: 99
Reputation: 6073
In MS SQL
, i think the below code will work.
SELECT DS.StaffId,COUNT(OI.OrderId) [Count]
FROM DeliveryStaff DS
JOIN Orders O ON DS.StaffId = O.DeliveryStaffId
JOIN OrderItems OI ON O.OrderId = OI.OrderId
GROUP BY DS.StaffId
Upvotes: 5
Reputation: 1058
Try this:
select StaffId, fName, lName, sum(Quantity)
from DeliveryStaff ds, Orders o, OrderItems oi
where StaffId = DeliveryStaffId
and o.OrderId = oi.OrderId
group by StaffId, fName, lName
Upvotes: -1