比较两列并在thrid中返回结果

时间:2016-07-22 12:02:39

标签: sql oracle

假设我有这张表:

--------------------------------------------------------------------------
| id | allowed_to_play_pokemon_go_after | last_played_pokemon_go |  name |
--------------------------------------------------------------------------
| 1  |                        20-JUL-16 |              19-JUL-16 |  Jhon |
--------------------------------------------------------------------------
| 2  |                        19-JUL-16 |              21-JUL-16 |  Bill |
--------------------------------------------------------------------------

现在我想做一个像这样的选择:

SELECT name, (last_played_pokemon_go > allowed_to_play_pokemon_go_after) as must_punish
FROM myTable;

哪里有'must_punish'必须bo一个布尔值(1/0)。

1 个答案:

答案 0 :(得分:2)

您可以使用case

SELECT name,
       (case when last_played_pokemon_go > allowed_to_play_pokemon_go_after then 1 else 0
        end) as must_punish
FROM myTable;

Oracle(数据库)没有布尔数据类型。一个数字应该没问题。