您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

BigQuery SQL排除不在空结果中

BigQuery SQL排除不在空结果中

不要使用not in。从语义上讲,这是违反直觉的。如果子查询中的 任何 值为NULL,则不返回任何行。

使用not exists代替;

select t1.accountid
from `table1` t1
where not exists (select 1
                  from table1 tt1
                  where tt1.accountid  = t1.accountid and
                        tt1.action <> 'Action8'
                 );

或使用group byhaving

select t1.accountid
from table1 t1
group by t1.accountid
having sum(case when action = 'Action8' then 1 else 0 end) = 0;
SQLServer 2022/1/1 18:46:12 有446人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶