如何根据SQL中的条件获取结果?

时间:2016-09-17 16:20:04

标签: sql oracle

考虑问题详细信息表有Overall_Issues_ID和Fixed_Issues_ID列。我需要根据以下某些条件得到结果。

条件:如果在任何一个Fixed_Issues_ID列中存在Overall_Issues_ID值,则应将这些ID视为固定,否则将其视为未固定。

enter image description here

我正在使用Oracle版本10 G.

2 个答案:

答案 0 :(得分:2)

使用不同的别名

连接两次相同的表
select i1.overall_issues_id, 
       case when i2.overall_issues_id is not null 
            then 'fixed'
            else 'not fixed'
       end as is_fixed
from issues_details i1
left join issues_details i2 on i2.fixed_issues_id = i1.overall_issues_id

SQLFiddle demo

答案 1 :(得分:1)

您可以在子查询中查找ID:

select 
  overall_issues_id as id,
  case when overall_issues_id in (select fixed_issues_id from issue_details fixed) 
    then 'Fixed' else 'Not Fixed' end as fixed
from issue_details;