多条款

时间:2017-02-08 07:17:26

标签: excel

我有一张这样的表

ID   Process  Work

A1   | 0 |       Done                                                                                                                                               
A1   | 1 |       Progress                                                                                                                                               
A2   | 0 |       Done  

我需要输出A1。当Process = 0和Work ='Done'时,仅表示该工作的ID。

如何在where condition中使用多个And语句?

2 个答案:

答案 0 :(得分:0)

您可以使用简单的查询,例如

Select * from table where (process = 0 AND work = 'Done') and  (work ='Progress' and process > 0)

肯定会给你A1

答案 1 :(得分:0)

由于您的描述"将仅输出A1,因为对于Process> 0 A2且A3具有Work = Done",我认为该要求实际上如下:

"只获取process = 0和work = done的条目,其中没有其他进程> 0 with work = done(和相同的id)。"

这可以用SQL表示如下:

select t1.* from table t1 where (t1.process = 0 AND t1.work = 'Done')
and t1.id not in (select t2.id from table t2 where t2.process > 0 and t2.work = 'Done')
相关问题