我写了一个查询来测试一个简单的线性回归,以获得两组权重测量之间的最佳拟合线.它应该有希望返回如下的结果,但它会抛出一个奇怪的错误
'ORA-00907缺少右括号'
和TOAD指向它所说的部分:
case ( when trn.wid_location = 28.3 then
Run Code Online (Sandbox Code Playgroud)
我一直在为缺少的括号进行梳理,但我认为这不是问题,因为如果我将case语句替换为
100 as mine,
Run Code Online (Sandbox Code Playgroud)
错误消失,查询执行.
有什么想法吗?
干杯,
汤米
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
)
Run Code Online (Sandbox Code Playgroud)
以下是我很高兴看到的结果
-- +----------+--------+----------+
-- | SITE | M | B |
-- +----------+--------+----------+
-- | CL | 0.900 | -1.0 |
-- +----------+--------+----------+
-- | DA | 0.950 | -1.5 |
-- +----------+--------+----------+
Run Code Online (Sandbox Code Playgroud)
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;
Run Code Online (Sandbox Code Playgroud)