按给定类型的user_ids排除记录集。得到了哪里查询,需要相反

时间:2013-02-11 03:22:37

标签: sql ruby-on-rails activerecord

如果我有一个续集声明,选择我想要排除的内容,如下所示:

e.where("events.user_id in (?) and type = 'Post'", some_ids)

我如何撰写排除这些内容的陈述?我可以在一行中编写它还是必须存储它们并通过id排除这些事件?

some_ids是一个user_ids数组

2 个答案:

答案 0 :(得分:2)

e.where("events.user_id not in (?) or type <> 'Post'", some_ids)

答案 1 :(得分:0)

“哪里不存在”是你最喜欢的三个词。例如,

select whatever
from wherever
where not exists 
(subquery goes here)