有一数据库,内容大致如下:
ID(PK) NAME TIME STATUS
1 ab .. wait
2 ab .. execute
3 ab .. end
4 cd .. wait
5 cd .. execute
6 ef .. wait
7 ef .. execute
8 ef .. end
每一个NAME相同的记录 如 数据库中有三条NAME为ab的记录,有三种状态, wait, execute, end.
现在需要要查找出状态只有wait,没有end的记录,比如NAME为 cd 的记录只有两条,状态是wait和 execute,没有end状态,请问要找出这样的记录SELECT语句要怎么写,请指点,谢谢~`
ID(PK) NAME TIME STATUS
1 ab .. wait
2 ab .. execute
3 ab .. end
4 cd .. wait
5 cd .. execute
6 ef .. wait
7 ef .. execute
8 ef .. end
每一个NAME相同的记录 如 数据库中有三条NAME为ab的记录,有三种状态, wait, execute, end.
现在需要要查找出状态只有wait,没有end的记录,比如NAME为 cd 的记录只有两条,状态是wait和 execute,没有end状态,请问要找出这样的记录SELECT语句要怎么写,请指点,谢谢~`
select a.[name]
from (select [name]
from tablename
where status = 'wait') a
left join (select [name]
from tablename
where status = 'end') b
on a.[name] = b.[name]
where b.[name] is null
from (select [name]
from tablename
where status = 'wait') a
inner join (select [name]
from tablename
where status <> 'end') b
on a.[name] = b.[name]