当访问者投票时,我会存储信息answer_id
,ip
等
我的网站访问者在多个民意调查中投票。
我想知道投票的访问者(answer_id(767))他们投票的其他内容。基于ip。让我们说answer_id = 767
表: poll_stat
`id` int(11) NOT NULL auto_increment,
`question_id` int(11) NOT NULL,
`answer_id` int(11) NOT NULL,
`ip` varchar(255) NOT NULL,
`date` date NOT NULL,
`country` text NOT NULL,
`time` int(11) NOT NULL,
`age` int(11) NOT NULL,
答案 0 :(得分:1)
我认为这对你有用。
select ip, question_id
from poll_stat
where ip in (select ip from poll_stat where answer_id = 767 group by ip)
and answer_id <> 767
修改强>
嗯......你可能会检查ip列上是否创建了INDEX
。如果不是这样,也许它不喜欢IN子句。我将重写为连接:
select ip, question_id
from poll_stat ps1
inner join (select ip from poll_stat where answer_id = 767 group by ip) ps2
on ps1.ip = ps2.ip
where answer_id <> 767