如果学生的标记是33或以上,我想显示'通过',如果小于33,我想显示'失败'。
我的表格是id,rollno,subject,marks
我要展示的是
记录:
id rollno subject marks
10 1253 english 67
期望的输出
id rollno subject marks status
10 1253 english 67 Pass
11 1247 computer 24 Fail
请告诉我查询
答案 0 :(得分:1)
for t-sql(MSSQL):
SELECT id, rollno, subject, marks,
case when marks >=33 THEN 'Pass'
else 'Fail'
end [Status]
FROM <TABLE NAME>
答案 1 :(得分:0)
通用解决方案:
select id, rollno, sbject, marks, 'Pass' as status from table_name where marks >= 33
union
select id, rollno, sbject, marks, 'Fail' as status from table_name where marks < 33
答案 2 :(得分:0)
这应该适用于Oracle db -
SELECT id,
rollno,
subject,
mark,
(
CASE
WHEN mark < 33
THEN 'FAIL'
ELSE 'PASS'
END) status
FROM table_name;