1

我编写了一个查询来测试一个简单的线性回归,以获得两组体重测量值之间的最佳拟合线。它应该有望返回如下结果,但它抛出了一个奇怪的错误

'ORA-00907 缺少右括号'

并且 TOAD 指向它说的部分:

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     |
--    +----------+--------+----------+
4

2 回答 2

5

T 认为 case 的语法不正确。

执行以下操作:

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; 
于 2009-08-07T05:07:59.387 回答
1

尝试去掉 case 语句中的两个括号。你不需要它们。

有可能:

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 
于 2009-08-07T05:06:53.540 回答