开发者

please help me construct this MYSQL Query (date / time) [closed]

开发者 https://www.devze.com 2023-01-01 22:41 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. 开发者_运维技巧 Closed 9 years ago.

I would like to construct a query that fetches results that occurred between NOW and 15 minutes ago, im getting a mysql error when I try the following , can you help me? thanks

SELECT *
 WHERE user_id = '000'
   AND date_time < now( )
   AND date_time > DATE_SUB( now( ) , INTERVAL 15 MINUTE) 

Error message:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE user_id = '000' AND date_time < now( ) AND date_time > DATE_SUB( now( ) ' at line 2


You need to select FROM a table :)


it lacks FROM TABLENAME

SELECT * FROM TABLENAME
WHERE user_id = '000'
AND date_time < now( )
AND date_time > DATE_SUB( now( ) , INTERVAL 15 MINUTE) 


You're missing the FROM statement

SELECT *
FROM myTable
WHERE user_id = '000'
AND date_time < now( )
AND date_time > DATE_SUB( now( ) , INTERVAL 15 MINUTE) 
0

精彩评论

暂无评论...
验证码 换一张
取 消