2009-08-07 3 views
1

두 가지 가중치 세트 사이에서 가장 잘 맞는 라인을 얻기 위해 간단한 선형 회귀를 테스트하는 쿼리를 작성했습니다. 그것은 희망 아래와 같은 결과를 반환해야하지만, 그것은 이상한 오류오라클 SQL - 이상한 'ORA-00907 오른쪽 괄호가 누락되었습니다'오류가 발생했습니다.

던지고 '누락 ORA-00907를 마우스 오른쪽 괄호'

하고 말한다 곳 두꺼비는 부분을 향해 가리키는 :

case (when trn.wid_location = 28.3 then 

나는 누락 된 괄호에 대해 빗질 해왔다. 그러나 case 문을 바꾸면 문제가 될 것이라고 생각하지 않는다.

100 as mine, 

오류가 사라지고 쿼리가 실행됩니다.

의견이 있으십니까?

건배, 여기

select 
     decode(wid_location,28.3,'CL',29.6,'DA') as site, 
     (n*sum_xy - sum_x*sum_y)/(n*sum_x_sq - sum_x*sum_x) as m, 
     (sum_y - ((n*sum_xy - sum_x*sum_y)/(n*sum_x_sq - sum_x*sum_x))*sum_x)/n as b 

from (
     select 
       wid_location, 
       sum(wids) as sum_x, 
       sum(mine) as sum_y, 
       sum(wids*mine) as sum_xy, 
       sum(wids*wids) as sum_x_sq, 
       count(*) as n 

     from (                  
       select 
         trn.wid_location, 
         con.empty_weight_total as wids,                  
         case ( 
           when trn.wid_location = 28.3 then con.empty_weight_total*0.900-1.0 
           when trn.wid_location = 29.6 then con.empty_weight_total*0.950-1.5 
           end     
          ) as mine 

       from widsys.train trn 
        inner join widsys.consist con 
        using (train_record_id) 

       where mine_code = 'YA' 
         and to_char(trn.wid_date,'IYYY') = 2009 
         and to_char(trn.wid_date,'IW') = 29 

           ) 

     group by wid_location 
    ) 

토미 그리고 내가

-- +----------+--------+----------+ 
-- | SITE  | M  | B  | 
-- +----------+--------+----------+ 
-- | CL  | 0.900 | -1.0  | 
-- +----------+--------+----------+ 
-- | DA  | 0.950 | -1.5  | 
-- +----------+--------+----------+ 

답변

5

T는 사건의 구문이 올바르지 않습니다 생각합니다.

과 같이 수행

SELECT last_name, commission_pct, 
    (CASE commission_pct 
    WHEN 0.1 THEN ‘Low’ 
    WHEN 0.15 THEN ‘Average’ 
    WHEN 0.2 THEN ‘High’ 
    ELSE ‘N/A’ 
    END) Commission 
FROM employees ORDER BY last_name; 
+0

와우를. 지금 그것은 나의 부분에 어리석은 순간이었다. –

1

이 경우 문에서 두 괄호 치우는 시도보고 드리겠습니다 결과입니다. 너는 필요 없어.

이 될 수 있습니다

case when trn.wid_location = 28.3 then con.empty_weight_total*0.900-1.0 
     when trn.wid_location = 29.6 then con.empty_weight_total*0.950-1.5 end as mine 
관련 문제