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