我有以下查询生成错误消息
Msg 209,Level 16,State 1,Line 4不明确的列名'p_id'
以下是有问题的查询。
SELECT *
from (select playerperform.p_id,player.first_name, SUM (playerperform.score)as totalgoal, RANK() OVER(ORDER BY SUM(playerperform.score)DESC) Rnk
from playerperform,player
Group by p_id
)as a
WHERE Rnk = 1
答案 0 :(得分:1)
显然,p_id
和playerperform
都有player
列。
至少,改变:
GROUP BY p_id
要
GROUP BY playerperform.p_id
您执行隐式CROSS JOIN
:
FROM playerperform,player
我怀疑应该是INNER JOIN
有一些条件,例如
FROM dbo.playerperform INNER JOIN dbo.player
ON playerperform.p_id = player.p_id
顺便说一下,p_id
是列的可怕名称......