0

我有下表

ID Name  Progress     Date
------------------------------
1  A1    First Stage  1/1/2013
2  A1    Second Stage 1/2/2013
3  A2    First Stage  1/1/2013
4  A2    Second stage 1/2/2013
5  A3    First Stage  1/2/2013
6  A1    Closed       1/5/2013

我想显示每个名称的阶段,除了最终关闭的名称。例如这个的输出应该是

ID Name  Progress     Date
------------------------------
3  A2    First Stage  1/1/2013
4  A2    Second stage 1/2/2013
5  A3    First Stage  1/2/2013

不是 A1,因为 A1 最终是关闭的。

我的查询显示Select * from table where Progress not like 'Closed'显然显示了除该行之外的所有结果。

谢谢

4

2 回答 2

1

使用子查询过滤您要排除的所有名称:

select distinct name from table where progress = 'Closed'

现在,在您的查询中使用它:

select *
from table
where name not in (select distinct name from table where progress = 'Closed');

希望这可以帮助你

于 2013-01-29T22:46:57.407 回答
0
SELECT x.* 
  FROM my_table x 
  LEFT 
  JOIN my_table y 
    ON y.name= x.name 
   AND y.progress = 'closed' 
 WHERE y.id IS NULL;
于 2013-01-30T00:12:31.043 回答