1
ここで私のエラーがどこにあるのかわかりません。SQLエラーメッセージ8120修正
Column 'Shipments.ShipmentOrderDate' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
ここで私のエラーがどこにあるのかわかりません。SQLエラーメッセージ8120修正
Column 'Shipments.ShipmentOrderDate' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
あなたはのでGROUP BY
を必要とする:これは質問です:
Write a SELECT statement that returns the following columns
a. ShipmentOrderDate
b. Clients Email Address
c. Column that calculates the Total Order called OrderTotal
d. A Column that uses the Rank() function to return a column named OrderTotalRank that
ranks the Order Total in Desc Order.
e. A column that uses the DenseRank() function to return a column called DenseRank that
ranks the Order Total in Desc Order.
そして、これは私がコード化されたものです:私は、コードを実行すると
SELECT ShipmentOrderDate, EmailAddress,
SUM(sh.ShipItemPrice * sh.Quantity) AS OrderTotalRank,
RANK() OVER (ORDER BY SUM(sh.ShipItemPrice * sh.Quantity) DESC) AS OrderTotalRank,
DENSE_RANK() OVER (ORDER BY SUM(sh.ShipItemPrice * sh.Quantity) DESC) AS DenseRank
FROM Clients AS c JOIN Shipments AS s
ON c.ClientID = s.ClientID
JOIN ShipItems AS sh
ON s.ShipmentID = sh.ShipmentID
が、私はこのエラーを取得しますSELECT
に集約関数があります。これらは、使用しているウィンドウ関数とは別のものです。
SELECT ShipmentOrderDate, EmailAddress,
SUM(sh.ShipItemPrice * sh.Quantity) AS OrderTotalRank,
RANK() OVER (ORDER BY SUM(sh.ShipItemPrice * sh.Quantity) DESC) AS OrderTotalRank,
DENSE_RANK() OVER (ORDER BY SUM(sh.ShipItemPrice * sh.Quantity) DESC) AS DenseRank
FROM Clients c JOIN
Shipments s
ON c.ClientID = s.ClientID JOIN
ShipItems sh
ON s.ShipmentID = sh.ShipmentID
GROUP BY ShipmentOrderDate, EmailAddress;
ここでGROUP BYはなぜ必要ですか?私はそれが問題だと思ったが、誰かが必要であるとは確信していなかった –