I'm struggling to understand why my query isn't returning any results, please could you take a look and let me know what I'm doing wrong:
SELECT * FROM sys_online_users WHERE last_active BETWEEN NOW() AND DATE_SUB(NOW(), INTERVAL 10 SECOND)
What I am trying to achieve is to show which users have been active within the last 10 seconds or any other time interval. However when I run the query I get no results, despite knowing that I have got updates in my table between the specified time range.
Yiu are going the wrong way with the between- first the ten seconds ago, and afterwards the now:
SELECT * FROM sys_online_users WHERE
last_active BETWEEN DATE_SUB(NOW(),
INTERVAL 10 SECOND)
AND NOW()
尝试这个:
SELECT * FROM sys_online_users WHERE last_active BETWEEN DATE_SUB(NOW(), INTERVAL 10 SECOND) AND NOW()
只有列放置错误,请尝试以下操作:
SELECT * FROM sys_online_users WHERE last_active BETWEEN DATE_SUB(NOW(), INTERVAL 10 SECOND) AND NOW()
I have tried below query it is working perfect.In your query please take more gap with second then fire query you will get desired result
SELECT * FROM sys_online_users WHERE last_active BETWEEN DATE_SUB(NOW(), INTERVAL 50 SECOND) AND NOW();
In this query i have added 50 second so we can identify easily.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.