2
任何人都可以指出我在哪裏搞亂查詢以及如何糾正它。我越來越我該如何解決組錯誤
錯誤是:
SQL Server數據庫錯誤:因爲它不是在聚合函數或GROUP BY子句中包含列「A.competitor_id」在選擇列表中無效。 號線,1列無0
SELECT A.competitor_id, A.Competitor_Name,
(((AVG(A.Final_Price_Shipping)/AVG(D.Final_Price_Shipping))*100)-100) as [Final Price Shipping Index],
(((AVG(A.Final_Price)/AVG(D.Final_Price))*100)-100) as [Final Price Index],
(((AVG(A.Regular_price)/AVG(D.Regular_price))*100)-100) as [Regular Price Index]
from
(SELECT A.competitor_id,C.Competitor_Name, COUNT(1) OVER (PARTITION BY A.competitor_id) as Row_Count,
avg(Final_Price) Final_Price,avg(Final_Price_Shipping) Final_Price_Shipping,
avg(Regular_price) as Regular_price ,SUM(A.Competitor_id) as cnt_NL
from [Tb_Competitor_Product_Info_New] A with (nolock)
inner join Tb_Competitor C on C.Competitor_Id=A.Competitor_ID
where A.Competitor_id in (1)
group by A.Competitor_ID,C.Competitor_Name) As A,
(SELECT A.competitor_id, COUNT(1) OVER (PARTITION BY A.competitor_id) as Row_Count,
avg(Final_Price) Final_Price,avg(Final_Price_Shipping) Final_Price_Shipping,
avg(Regular_price) as Regular_price ,SUM(A.Competitor_id) as cnt_NL
from [Tb_Competitor_Product_Info_New] A with (nolock)
where A.Competitor_id in (2,3,4,5,6,7,8,9)
group by A.Competitor_ID) As D
您使用的是.Competitor_ID在group by子句中,並且您正在使用小型案例選擇它,不確定sql是否不區分大小寫,同時錯誤意味着您需要選擇要在group by子句中使用的字段 –