图表:
查询加入:
SELECT DISTINCT c.CustomerID, c.FirstName , sh.DueDate, p.ProductID,p.ListPrice
FROM SalesLT.Customer c
INNER JOIN SalesLT.SalesOrderHeader sh
ON c.CustomerID = sh.CustomerID
INNER JOIN SalesLT.SalesOrderDetail sd
ON sh.SalesOrderID = sd.SalesOrderID
INNER JOIN SalesLT.Product p
ON sd.ProductID = p.ProductID
Order BY ListPrice Desc
输出:
期望的结果:
对于所需的输出:
答案 0 :(得分:1)
我想你想要:
SELECT c.CustomerID
, c.FirstName
, sh.DueDate
, MAX(p.ProductID) ProductID
,p.ListPrice
FROM SalesLT.Customer c
INNER JOIN SalesLT.SalesOrderHeader sh
ON c.CustomerID = sh.CustomerID
INNER JOIN SalesLT.SalesOrderDetail sd
ON sh.SalesOrderID = sd.SalesOrderID
INNER JOIN SalesLT.Product p
ON sd.ProductID = p.ProductID
GROUP BY
, c.FirstName
, sh.DueDate
, p.ListPrice
Order BY ListPrice Desc
并不是说它作为查询有多大意义,但我想你想知道这种方法?可能你现在有一个很好的答案,但它鼓励我们如果你勾选一个适当的回答,我会花时间回答,谢谢