2010-06-13 17 views
0

分組功能,您好我嘗試運行:不是單組同時使用REGR_SLOPE

select 
    year, 
    regr_slope(sum(sale_count),year) as slope, 
from products 
group by year 

它拋出「00937. 00000 - ‘不是一個單一羣組功能’」。當我刪除從選擇條款問題消失的一年。我不應該能夠選擇我正在分組的列嗎?

Oracle 11.2 sqldeveloper

ty求助!

+0

ORA-00937:http://www.techonthenet.com/oracle/errors/ora00937.php – 2010-06-13 23:40:34

回答

2

這是因爲你試圖使用的功能(REGR_SLOPE),其可以是一種聚合(或分析)功能上的另一合計(SUM)的結果 - 使用:使用WITH

SELECT x.year, 
     REGR_SLOPE(sum_sales, x.year) AS slope 
    FROM (SELECT y.year, 
       SUM(y.sale_count) AS sum_sales 
      FROM PRODUCTS y 
     GROUP BY y.year) x 
GROUP BY x.year 

替代子句(Oracle 9i +):

WITH sums AS (
    SELECT y.year, 
      SUM(y.sale_count) 
     FROM PRODUCTS y 
    GROUP BY y.year) 
    SELECT x.year, 
     REGR_SLOPE(sum_sales, x.year) AS slope 
    FROM sums x 
GROUP BY x.year 
1

你試過這樣嗎?

select 
    a.year 
, regr_slope(a.sale_count,a.year) as slope, 
from (SELECT year 
      , sum(sale_count) sale_count 
     FROM products 
     GROUP BY year) a 
相關問題