我正在尝试获取没有status_mvf = 88
的骨灰盒status_mvf urn desc date
88 104 no show 2017-03-06
9 104 late 2017-03-07
2 104 on time 2017-03-08
2 210 on time 2017-03-06
2 210 on time 2017-03-07
9 320 late 2017-03-06
SELECT
a.Status_Mvf,
p.URN,
v.ADMIT_DATE
FROM APPOINTMENT
WHERE Status_Mvf <> '88'
--group by p.urn,
ORDER BY URN, STATUS_MVF
期望的结果 - 没有骨灰盒104因为它有88
status_mvf urn desc date
2 210 on time 2017-03-06
2 210 on time 2017-03-07
9 320 late 2017-03-06
答案 0 :(得分:0)
You can use not exists
:
select a.*
from appointment a
where not exists (select 1 from appointment a2 where a2.urn = a.urn and a2.status_mvf = '88');
答案 1 :(得分:0)
尝试这样的事情(使用NOT IN语句):
SELECT a.Status_Mvf, p.URN, v.ADMIT_DATE
FROM APPOINTMENT a
WHERE urn NOT IN
(
SELECT a2.urn FROM APPOINTMENT a2
WHERE a2.Status_Mvf = '88'
)
ORDER BY URN, STATUS_MVF