Mysql 查询我想知道投票的访问者,例如 ( answer_id (767) ) 他们投票的其他内容

标签 mysql

当访客投票时,我存储信息answer_idip

我的网站访问者在多个投票中投票。

我想知道投票的访问者,例如 ( 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,

最佳答案

我认为这对你有用。

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

关于Mysql 查询我想知道投票的访问者,例如 ( answer_id (767) ) 他们投票的其他内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12232422/

相关文章:

mysql - 每第二次命中获得 "Access denied for user..."

php - 使用 session 变量来区分网站用户的类型,例如管理员或成员(member)

MySQL父子一查询选择

mysql - 在laravel中编写连接同一个表的代码

Python 程序突然结束,我无法破译错误

python - 当多个线程写入 mysql 中的单个表时会发生什么?

php - 向 osCommerce 中的订购产品添加新列

mysql - 执行数据库查询时出错

php - 如何使用 Ones 数据搜索两个 Mysql 表

MYSQL:基于同一张表的条件,不同列中的相同值