ORA-00907:添加新列时缺少右括号

时间:2013-03-14 17:01:12

标签: sql oracle

create table student (
       name varchar2(20),
       s1 number(3),
       s2 number(3),
       s3 number(3)
);

insert into student values('ashok',50, 90, 70);

select name,s1,s2,s3, s1+s2+s3 "Total" 
from student;

select name,s1,s2,s3,if((s1+s2+s3)>(105)){'pass'}   "Total" 
from student 
group by name;

任何人都可以帮助如何打印新专栏学生通过或未通过查看每个科目。

2 个答案:

答案 0 :(得分:1)

试试这个:

select distinct
    name,
    s1,
    s2,
    s3,
    case when (s1+s2+s3) > 105 then 'pass'
        else 'fail'
        end as "Total" 
from student;

答案 1 :(得分:1)

你不能这样使用。你正在寻找的语法词是CASE。

SELECT 
  name, s1,s2,s3,
  CASE
    WHEN (s1+s2+s3)>105 THEN 'Pass'
    ELSE 'Fail'
  END as 'Total'
FROM 
  student