简体   繁体   English

SQL从一张表中选择具有相同ID的多个条件

[英]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 message_thread_id status地位
229 229
229 229 delivered发表
229 229 sent发送
229 229 delivered发表
229 229 delivered发表
240 240 sent发送
240 240 sent发送
1044 1044
1044 1044
1044 1044
1068 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM