获取本周和上周的访客总数


Get the total amount of visitors under this week and last week

我想获取本周和上周的访客总数,我得到了一个可能的解决方案,但它不会显示正确的数量。根据HeidiSQL的数据,本周有91名访问者,上周有383名访问者。下面的代码显示,本周有 88 名访客,上周有 56 名访客。

SELECT COUNT(date_lastactive) FROM visitors WHERE DATE(date_lastactive) = '".date('Y-m-d', strtotime('this week'))."'

SELECT COUNT(date_lastactive) FROM visitors WHERE DATE(date_lastactive) = '".date('Y-m-d', strtotime('last week'))."'

我该怎么做才能发出此SQL请求以获得正确数量的访问者,还是HeidiSQL是这里的骗子?

提前谢谢。

您只选择一天。

SELECT COUNT(date_lastactive) FROM visitors WHERE DATE(date_lastactive) > '".date('Y-m-d', strtotime('monday'))."' && DATE(date_lastactive) < '".date('Y-m-d', strtotime('sunday'))."'

我的代码不正确,但你可以看到这一点。