根据mysql中的先前记录检索记录

时间:2013-10-29 09:40:43

标签: mysql

在进行大量搜索后,我无法找到所需的结果。 我有一个表 tasktransit ,其中包含以下数据:

+---------------+--------+------------+-------------+-------------+------------+
| tasktransitid | taskid | activityid | newsequence | status      | dependency |
+---------------+--------+------------+-------------+-------------+------------+
|             1 | RH001  |          1 |           1 | Not Started |            |
|             2 | RH001  |          2 |           2 | Completed   |            |
|             3 | RH001  |          3 |           4 | Not Started |            |
|             4 | RH001  |          4 |           3 | Not Started |            |
|             5 | RH002  |          3 |           1 | Completed   | NULL       |
|             6 | RH002  |          4 |           2 | Not Started |            |
|             7 | RH003  |          3 |           1 | Not Started | NULL       |
|             8 | RH004  |          4 |           2 | Not Started | NULL       |
+---------------+--------+------------+-------------+-------------+------------+

这里newsequence对于一种taskid是唯一的。

I want to get the the taskid where 
activityid=4 AND
status="Not Completed" AND
status="Completed" of previous newsequence.

因此,使用上述类型的sudo代码,我想要一个具有以下值的结果

taskid    | activityid
 1. RH001  |  4

 2. RH002  |  4

任何帮助都会得到满足。

1 个答案:

答案 0 :(得分:1)

我没有找到状态“未完成”。您将条件where子句添加为

status="Not Completed" AND status="Completed"

您是否希望列表未开始或已完成?

  status="Not Started" OR status="Completed"