我有一个名为jobs的Oracle表。在这张表中,我有2个工作,JOB 1和JOB 2.我需要根据以下条件获得一份工作。
IS_ASSIST JOB_PROCESS
必须有JOB_PROCESS_STATE = '0'
。 JOB
1和2都满足了这一点。IS_ASSIST
的状态为0,然后获得具有JOB_PROCESS = IS_PULLAHEAD
和JOB_PROCESS_STATE = 1
的作业。这应该是ID = 4
的最后一行。我如何在查询中写下这些条件?这是一个仅应用第一个条件的示例。我怎么也应用第二个条件?
SELECT JOB_ID
FROM JOB
WHERE JOB_PROCESS = 'IS_ASSIST'
AND JOB_PROCESS_STATE = '0'
工作表:
+-------------------------------------------+
|ID |JOB_ID| JOB_PROCESS |JOB_PROCESS_STATE|
+-------------------------------------------+
| 1 | 1 | IS_ASSIST | 0 |
|-------------------------------------------|
| 2 | 1 | IS_PULLAHEAD | 0 |
|-------------------------------------------|
| 3 | 2 | IS_ASSIST | 0 |
|-------------------------------------------|
| 4 | 2 | IS_PULLAHEAD | 1 |
+-------------------------------------------+
提前谢谢!
答案 0 :(得分:1)
从此查询中获取第一条记录
select JOB_ID
from JOB
where JOB_ID IN
(
SELECT JOB_ID
FROM JOB
WHERE JOB_PROCESS = 'IS_ASSIST' AND JOB_PROCESS_STATE = '0'
GROUP BY JOB_ID
)
ORDER BY case when JOB_PROCESS = IS_PULLAHEAD AND JOB_PROCESS_STATE = 1
then 0
else 1
end