tags:

views:

2047

answers:

2

Hi folks,

I've written a query to test out a simple linear regression to get the line of best-fit between two sets of weight measures. It should hopefully return results like below, but it's throwing a strange error

'ORA-00907 Missing Right Parenthesis'

and TOAD is pointing towards the part where it says:

case ( when trn.wid_location = 28.3 then

I've been combing it over for missing parenthesis but I don't think that's the issue because if I replace the case statement with

100 as mine,

the error disappears and the query executes.

Any thoughts?

Cheers,

Tommy

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
     )

And here are the results i'd be happy to see

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

Try getting rid of both parens in the case statement. You don't need them.

It can be:

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
jle
+1  A: 

T think the syntax of the case is not correct.

Do something like:

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;
tuinstoel
wow. now that was a dumb moment on my part.