2013-10-25 81 views
-2

我有以下查詢其產生錯誤消息消息209,級別16,狀態1,行4不明確的列名稱P_ID「

消息209,級別16,狀態1,行4不明確的列name'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

我希望把球員的名字,但它給了我這個錯誤 – user2914820

+0

先生,我希望把球員名字還我怎樣才能把那個?玩家的名字是在其他表中調用「玩家」 – user2914820

回答

1

顯然你必須在這兩個playerperformplayer一個p_id列。

在最低限度,變化:

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是一列一個可怕的名字......

+0

對不起,我不明白 – user2914820

+0

@ user2914820對不起,但如果你不明白我的答案,那麼我不知道如何幫助你。 –

+0

SELECT * from(選擇playerperform.p_id,player.first_name + last_name,SUM(playerperform.score)as totalgoal,RANK()OVER(ORDER BY SUM(playerperform.score)DESC)from playerperform的Rnk INNER JOIN player ON playerperform.p_id = player.p_id Group by playerperform.p_id,player.first_name + last_name)作爲WHERE Rnk = 1 – user2914820

相關問題