2015-05-29 28 views
1

使用下面的模式,編寫一個查詢,其中列出了從銷售人員購買的項目的所有銷售總值,這些銷售人員的銷售人員的初始中間值相同。你的查詢應該返回一個結果。外部連接上的T-SQL過濾器

quantityprice列均爲intsSales - Employee鏈接在EmployeeID - SalesPersonIDenter image description here

+1

氣味像功課...你嘗試過什麼? –

+0

向我們展示一些代碼。 – PiotrWolkowski

+0

我已嘗試選擇總和(s.Quantity * p.Price)作爲TotalSales from Sales s 加入產品p on s.ProductID = p.ProductID 其中s.SalespersonID in(選擇e.salespersonid from employees e join customers c on e.MiddleName = c.MiddleName),但是我需要添加一個條件,使其只有s.SalespersonID在銷售表中具有相應的C.CustomerID ... – Dvintila

回答

1

像這樣的東西應該工作:

select sum(s.Quantity * p.Price) as TotalSales 
from Sales s 
join Products p on s.ProductID = p.ProductID 
join Customers c on s.CustomerID = c.CustomerID 
join Empleyees e on s.SalesPersonID = e.EmployeeID 
where c.MiddleInitial = e.MiddleInitial