[英]Condition for Selecting multiple columns and rows
我该如何选择所有在upload_value中具有upload_key = host和cnn的主机的视频,并发送= 0
+----------+---------+------------+--------------+
| video_id | meta_id | upload_key | upload_value |
+----------+---------+------------+--------------+
| 1 | 6 | host | cnn |
| 1 | 7 | send | 0 |
+----------+---------+------------+--------------+
您可以在下面尝试-
select video_id
from tablename where (upload_key,upload_Value) =('host','cnn')
and exists (select 1 from tablename where (upload_key,upload_Value)=('send','0'))
选择所有在upload_value中具有upload_key =主机且cnn的视频,并发送= 0
一种方法是聚合并having
:
select video_id
from t
where upload_key in ('host', 'send')
group by video_id
having sum( upload_key = 'host' and upload_value = 'cnn' ) > 0 and
sum( upload_key = 'send' and upload_value = '0' ) > 0;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.