我有一张桌子,看上去如下(简化):
名称@ status
app-1 \x{e76f}
app-1 \x{e76f}运行
app-1 \x{e76f}运行
app-1 \x{e76f}运行
app-1 / finish
AP-2\x{e76f}
AP-2+运行
AP-2+运行
现在,我想过滤所有的应用程序,有“开始”的状态和没有“完成”。对于上面的例子,结果应该是"app-2“。
我不知道如何进行比较,而另外使用condition...it确实给了我一些困难。我希望有人能帮我?!
发布于 2014-03-15 22:49:36
select name from _table t1
where t1.status = 'start'
and not exists (
select name from _table t2
where t1.name = t2.name
and t2.status = 'finish'
)
发布于 2014-03-15 22:26:14
试着做这样的事情:
SELECT * FROM table_name
WHERE status = 'run' and name NOT IN
(SELECT name FROM table_name WHERE status = 'finish')
发布于 2014-03-15 22:29:48
不确定您正在使用的是哪个关系数据库,但查询将类似:
Select AppStatus.Name
From (
Select Name, Started, Finished
Sum(Case When status = 'start' then 1 else 0 end) as Started,
Sum(Case When status = 'finish' then 1 else 0 end) as Finished,
From Table
Group By Name
) as AppStatus
Where AppStatus.Started > 0 and AppStatus.Finished > 0
更新:如果您假设所有行都将以开始开始,并有零或多个运行,然后完成,这也将工作,而且要简单得多!
Select Distinct(Name)
From Table Where Name Not In (
SELECT Name
FROM Table
WHERE Status = 'finish')
https://stackoverflow.com/questions/22430471
复制相似问题