MYSQL 相同列的基本条件聚合

MYSQL basic conditional aggregation for same Columns

我遇到了以下问题,我不知道该如何解决。

我需要根据两个条件进行筛选 + 相同 属性

获取事件为“paymentFailed”且事件不是“paymentSuccess”的用户

id  name    event             transaction_number    
2   John    paymentFailed         002   
3   John    paymentInProcess      003   
4   John    paymentStucked        004   
5   John    paymentSuccess        005   
6   Jane    paymentFailed         006   
7   Jane    paymentSuccess        007   
8   Reese   paymentFailed         008   
9   Reese   paymentFailed         009   
10  Reese   otherPayment          010   

类似这样(当 paymentSuccess 不存在时)

SELECT * FROM USERS where event != "paymentSuccess" AND event = "paymentFailed"

结果:

id  name    event             transaction_number    
8   Reese   paymentFailed         008   

(当paymentSuccess存在时)

SELECT * FROM USERS where event = "paymentSuccess" AND event = "paymentFailed"

结果:

id  name    event             transaction_number    
------------------------ Empty table -----------------------

使用NOT EXISTS:

SELECT u1.* 
FROM USERS u1 
WHERE u1.event = 'paymentFailed'
  AND NOT EXISTS (SELECT 1 FROM USERS u2 WHERE u2.name = u1.name AND u2.event = 'paymentSuccess')