2013-04-26 51 views
0

嘗試查看哪個玩家獲得了最多的目標。無法讓查詢起作用

Player_id 
Goals. 

我嘗試了以下聲明:

select player_id, sum(goals) as total 
from matchstat 
group by player_id 
order by total desc limit 1; 

,但我得到的錯誤:

SQL command not properly ended.

有誰看到在查詢的問題?

+1

什麼RDBMS使用的是? – 2013-04-26 19:37:58

+0

是否適用於MySql? – 2013-04-26 19:42:43

回答

2

Oracle不支持限制條款。嘗試

SELECT * 
FROM (SELECT "player_id", 
       SUM("goals") AS total 
     FROM matchstat 
     GROUP BY "player_id" 
     ORDER BY total DESC) a 
WHERE ROWNUM <= 1 

See a demo

+0

什麼讓你知道OP使用Oracle的線索? – 2013-04-26 19:52:31

+1

@ PM77-1 ['SQL命令未正確結束。](https://www.google.com/search?q=SQL+command+not+properly+ended) – Kermit 2013-04-26 20:05:46

+0

完美運行!非常感謝! – user2325158 2013-04-26 20:45:52