[英]SQL select where multiple condition by same id from one table
Please help me, I have a table like below and I want to get data by id with status 'sent' and ' ' only and not with status 'delivered'.请帮助我,我有一个如下表,我想通过 id 获取数据,状态为“已发送”和“已发送”,而不是状态为“已交付”。
message_thread_id ![]() |
status![]() |
---|---|
229 ![]() |
|
229 ![]() |
delivered![]() |
229 ![]() |
sent![]() |
229 ![]() |
delivered![]() |
229 ![]() |
delivered![]() |
240 ![]() |
sent![]() |
240 ![]() |
sent![]() |
1044 ![]() |
|
1044 ![]() |
|
1044 ![]() |
|
1068 ![]() |
delivered![]() |
use NOT EXISTS
使用
NOT EXISTS
SELECT * FROM mytable a WHERE NOT EXISTS(
SELECT 1 FROM mytable b
WHERE a.message_thread_id = b.message_thread_id
AND status = 'delivered'
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.