显示mysql的具体结果

时间:2013-01-29 22:41:47

标签: mysql

我有下表

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'显然会显示除该行之外的所有结果。

由于

2 个答案:

答案 0 :(得分:1)

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

select distinct name from table where progress = 'Closed'

现在,在查询中使用它:

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

希望这有助于你

答案 1 :(得分: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;