包含table1中的所有记录,仅包含来自table2的ID字段相等的记录。
Select
Count(uno.itemID) As [Merchandise Sold],
uno.salesmanName As [Who Got Sale],
COUNT(duo.SalesCancelled) As [Bring it Back]
FROM table1 uno
INNER JOIN table2 duo
ON uno.itemID = duo.itemID
Group By uno.salesmanName
我尝试过内心,右边,左边,但没有得到预期的结果
答案 0 :(得分:1)
我想你想要一个left join
,因为你说你想把所有内容保存在第一个表中:
Select Count(uno.itemID) As [Merchandise Sold],
uno.salesmanName As [Who Got Sale],
COUNT(duo.SalesCancelled) As [Bring it Back]
FROM table1 uno LEFT JOIN
table2 duo
ON uno.itemID = duo.itemID
Group By uno.salesmanName;