Oracle SQL - 如何在不显示显式值的情况下格式化输出

Oracle SQL - How to format output without showing the explicit value

我正在查询 table 的考试成绩。如果分数超过 50%,则学生通过考试。如果考试分数高于 50%(即考试通过),我希望查询的输出显示 1,如果分数低于 50%(即考试失败),则显示 0。我不想显示实际的考试成绩。

    TURN THIS               INTO                 THIS

Exam no. Score Exam no. Score 1 37% => 1 0 2 84% 2 1 3 76% 3 1

我该怎么做?我找到了几篇关于使用空格、换行符、重命名列等格式化结果的文章和页面,但我不知道如何使用 "representational values"。

有没有一种方法可以编写查询,使结果看起来像上面示例中的结果?

您可以使用 CASE 表达式:

select exam_no, 
       case 
          when score >= 50 then 1
          else 0
       end as score
from the_table;