答案 0 :(得分:2)
产品数量大于5
SELECT ProductId
FROM ProductsSales
HAVING SUM(QuantitySold) > 5
用它来完成剩下的工作:
SELECT s.FirstName, s.LastName, s.SIN, p.ProductDescription, ps.UnitSalesPrice, ps.QuantitySold
FROM ProductsSales ps
LEFT JOIN Products p on p.ProductID = ps.ProductID
LEFT JOIN Salesmen s on s.SalesmaneID = ps.SellerID
WHERE ps.ProductID IN
(
SELECT ProductId
FROM ProductsSales
GROUP BY ProductId
HAVING SUM(QuantitySold) > 5
)
答案 1 :(得分:1)
SELECT a.FirstName, a.LastName, a.SIN, c.ProductDescription, b.UnitSalesPrice, b.QuantitySold
FROM Salesmen a
LEFT JOIN ProductsSales b
ON a.SalesmanId = b.SellerId
LEFT JOIN Products c
ON b.ProductId = c.ProductId
WHERE b.QuantitySold > 5
答案 2 :(得分:1)
Select a.FirstName, a.LastName, a.SIN From Salesmen as a,
c.ProductDescriptio, c.Price, b.sum(QunatitySold)
inner join ProductSales as b on a.Salesmanid = b.sellerid
inner join Products as c on c.ProductId = b.ProductId
having b.sum(QunatitySold)> 5
group by a.FirstName, b.ProductDescription
答案 3 :(得分:1)
布拉德,
欢迎使用SQL。在我刚开始的时候加入我这是一次可怕的经历,但它真的很容易。一般概念是:
选择加入
如果要查看两个表之间通用的所有记录,可以使用和JOIN
。如果您想要合并这两个表,但仍然显示您使用的所有记录LEFT JOIN
基本语法是
SELECT fieldnames FROM tablename alias
JOIN othertable alias ON firstalias.field = secondalias.field
--Example
SELECT animal, food, idtag from animals a
JOIN food f on a.animalid = f.animalid
这假设您在动物桌和食物桌中都有一个共同的野生动物。理想情况下,您还应该使用别名为字段名称添加前缀,以便更容易理解:a.animal, f.food
你继续前进,直到你加入了你需要的所有桌子。 确保只请求您想要的字段名称
希望有所帮助