我有一个包含三列的表格:
(JobNo,ProgramId& Status)
JobNo
有很多ProgramId
,每个ProgramId
都有Status
我只需要检索那些JobNo
ProgramId
JobNo
所有Status
JobNo
=“已发送”的内容。
从给定的图片中,JobNo
(1& 4)只应输出ProgramId
(1& 4)Status
的{{1}} =“已发送”
答案 0 :(得分:1)
您的问题建议group by
与having
:
select jobid
from t
group by jobid
having min(status) = max(status) and min(status) = 'delivered';
答案 1 :(得分:1)
尝试这样的事情(未经测试):
SELECT JobNo
FROM MyTable
GROUP BY JobNo
HAVING SUM(IIF(Status = 'Delivered', 0 , 1)) = 0