0
如果我有一个续集语句选择我想排除这样的内容:通过给定类型的user_id排除一组记录。拿到了其中的查询,需要相反
e.where("events.user_id in (?) and type = 'Post'", some_ids)
如何编写排除那些说法?我可以将它写在一行中,还是必须存储这些并通过ID排除这些事件?
some_ids是user_ids
如果我有一个续集语句选择我想排除这样的内容:通过给定类型的user_id排除一组记录。拿到了其中的查询,需要相反
e.where("events.user_id in (?) and type = 'Post'", some_ids)
如何编写排除那些说法?我可以将它写在一行中,还是必须存储这些并通过ID排除这些事件?
some_ids是user_ids
e.where("events.user_id not in (?) or type <> 'Post'", some_ids)
数组 “其中不存在” 是你最喜爱的词语。例如,
select whatever
from wherever
where not exists
(subquery goes here)
虽然它起作用,但它不一定是最有效的(取决于查询的其余部分) – 2013-02-11 03:27:29