2012-11-11 117 views
1

TIA對於任何幫助/建議/進一步閱讀。SQLDev限制結果

我想讓SQLDev做客戶有多少包的計數,然後只顯示這些結果的前10名。

所以我有這個....

select pickup_customer , count (pickup_customer) 
from 
(select pickup_customer, count (pickup_customer) 
    from manifest 
    order by count (pickup_customer) desc) 
where ROWNUM <= 10 
group by pickup_customer 
order by count (pickup_customer) desc 

隨着那我得到「不是一個單一的分組功能」和它的消失錯了,我想不通。可能非常簡單的修復,我現在看不到它!

編輯:我已經試過這段代碼,但現在我得到一個'缺少右括號'錯誤!

select pickup_customer , count (pickup_customer) 
from 
(select pickup_customer, count (pickup_customer) --sub-query which pre-orders the results for rownum to then limit. 
    from manifest 
    order by count (pickup_customer) desc 
    group by pickup_customer) 
where ROWNUM <= 10 -- limits the results to be only the top 10 
+2

您的訂單和羣組在第二個查詢中是錯誤的。 – Ben

回答

2

以下查詢應該可以工作。

SELECT pickup_customer, COUNT (pickup_customer) 
FROM enrollment 
WHERE ROWNUM <= 10 
GROUP BY pickup_customer 
ORDER BY COUNT (pickup_customer) DESC