1

我在使用 ANY 进行查询时遇到了一个小问题。

Select *, count(*) as m 
from mp_bigrams_raw 
where date_parsed=051213 
and art_source='f' 
and bigram != ANY(select feed_source from mp_feed_sources) 
group by bigram 
order by m DESC 
limit 50;

查询运行,但不排除在子查询中找到的项目。

原始查询在subquery. 一旦我添加了更多,我就会收到超过 1 行的错误。

Select *, count(*) as m 
from mp_bigrams_raw 
where date_parsed=051213 
and art_source='f' 
and bigram != (select feed_source from mp_feed_sources) 
group by bigram 
order by m DESC 
limit 50;

从那里我添加了 ANY 并且查询运行但似乎忽略了!=。我猜我在这里遗漏了一些东西。

谢谢

4

3 回答 3

2

你为什么不使用NOT IN

Select *, count(*) as m 
from mp_bigrams_raw 
where date_parsed=051213 
and art_source='f' 
and bigram NOT IN(select feed_source from mp_feed_sources) 
group by bigram 
order by m DESC 
limit 50;
于 2013-05-12T12:41:52.620 回答
0

条件ANY返回true(据文档所说),只要条件适用true于 的任何条目subselect,因此如果这些选定字段之一是!= bigram子句评估为true

NOT IN是你想要的,所以 bigram 不在选定值列表中。

于 2013-05-12T12:47:51.767 回答
0

尝试将 a与 aleft join一起使用is null

Select r.*, count(*) as m 
from mp_bigrams_raw r
left join mp_feed_sources f on f.feed_source = r.bigram 
where r.date_parsed=051213 
  and r.art_source='f' 
  and f.feed_source is null
group by r.bigram 
order by m DESC 
limit 50;
于 2013-05-12T12:44:13.213 回答