Hello Stack Overflow社区!我在想办法消除查询中的重复客户方面遇到了一些麻烦。而不是报告与同一客户提出十五次,我试图仅列出一次,而在德国。我在下面粘贴了我的代码,非常感谢任何建议!
select distinct s.CompanyName 'Company Name', 'Supplier' 'Partner Type',
s.ContactName 'Contact Name', s.Address, s.City,
s.Country, s.PostalCode 'Postal Code', s.Phone
from Suppliers s
inner join Products p
on s.SupplierID = p.SupplierID
inner join OrderDetails od
on p.ProductID = od.ProductID
inner join Orders o on od.OrderID = o.OrderID
where (s.Country = 'Germany')
Union
Select distinct c.CompanyName 'Company Name', 'Customer' 'Partner Type',
c.ContactName 'Contact Name', c.Address, C.City,
c.Country, c.PostalCode 'Postal Code', s.Phone
from Suppliers s
inner join Products p
on s.SupplierID = p.SupplierID
inner join OrderDetails od
on p.ProductID = od.ProductID
inner join Orders o
on od.OrderID = o.OrderID
inner join Customers c
on o.CustomerID = c.CustomerID
where (c.Country = 'Germany')
答案 0 :(得分:0)
我的问题是客户有多个电话号码,我删除了电话号码,这解决了重复。
答案 1 :(得分:0)
你在第二个查询部分使用了错误的电话表(s.Phone而不是c.Phone)。