I have a table with with 3 fields : id (int 11), user (varchar 255) and data (DATETIME).
I need somethings like :
SELECT user FROM counter WHERE date&g开发者_StackOverflowt;'ACTUAL DATA - 3 MINUTS'
So i can return all username with data between the actual data - 3 minuts and the actual data. Like return all username between 2010-12-22 18:32:00 and 2010-12-22 18:35:00
How can I do it with MySql?
Yes, you need to use the SUBTIME() function.
SELECT user FROM counter WHERE date > SUBTIME( 'yourdate', '0:03' );
EDIT
Since you changed your question here is an updated answer:
SELECT user FROM counter WHERE date BETWEEN SUBTIME( 'yourdate', '0:03' ) and 'yourdate'
SELECT user FROM counter WHERE date > DATE_SUB(dateColumn, INTERVAL 3 MINUTE)
SELECT user FROM counter WHERE date BETWEEN NOW() - INTERVAL 3 MINUTE AND NOW()
精彩评论