0

有两个表节点:

nid INT(10)
type (VARCHAR(32))

node_hit_count

nid INT(10)
totalcount (bigint(20))

我需要nidnode表中选择所有不在node_hit_count表中且WHERE node类型等于featurehome或的 scompetition

我尝试过的,它错了,我的想法会爆炸:/

select * from node left join node_hit_counter on node.nid=node_hit_counter.nid 

where hit.nid is null and node.type IN ('feature', 'home', 'competition')
4

2 回答 2

2

子句hit.nid中的内容是什么。WHERE您必须WHERE node.nid IS NULL像这样使用:

select node.*
from node 
left join node_hit_counter on node.nid = node_hit_counter.nid 
where node.nid is null 
  and node.type IN ('feature', 'home', 'competition');

或者:

SELECT *
FROM node
WHERE nid NOT IN(SELECT nid FROM node_hit_counter WHERE nid IS NOT NULL)
  AND type IN ('feature', 'home', 'competition');
于 2012-12-10T14:25:06.843 回答
1

试试这个,你可以在 where 子句中使用你的 hit.nid :o)

select n.* 
from node n
left join node_hit_counter hit on n.nid=hit.nid 
where hit.nid is null 
and n.type IN ('feature', 'home', 'competition')
于 2012-12-10T14:26:42.710 回答