我在从 MySQL 数据库计算平均每日访问者时遇到了一些问题。我有一个自动填充 0 或 1 的列,具体取决于访问者是真正的访问者还是机器人。我的查询看起来像这样
SELECT
COUNT( * ) / COUNT( DATEDIFF( NOW( ) ,
SELECT *
FROM mw_visitors
WHERE bot = 0
ORDER BY ID ASC
LIMIT 1 ) )
FROM mw_visitors
WHERE bot = 0
但它不起作用。我的 PHPMyAdmin 告诉我,“SELECT * FROM mw_visitors where bot = 0 ORDER..”处的语法有错误。我在网上搜索过,但没有找到正确的东西。
编辑:结构http://pastebin.com/dm4Hjukr 获得真实的人类访客:
SELECT COUNT(DISTINCT `ip`) AS `visits`
FROM `mw_visitors` WHERE `bot` = 0 AND `time` BETWEEN
(SELECT `time` FROM `mw_visitors` WHERE `bot` = 0 ORDER BY `ID` ASC LIMIT 1) AND NOW()