开发者

sql query - how to filter results from last hour? [closed]

开发者 https://www.devze.com 2023-03-19 11:13 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_JAVA百科 Closed 11 years ago.

I would only like to get only the data from the last hour. the query should be something like that...

SELECT some_date_related_data FROM some_table
WHERE time > now() - (1hour)

how can i achieve that?

Thanks!


Since you used NOW(), I'm guessing this is about MySQL. Then I'd suggest reading the manual :-)

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html


For MySQL:

WHERE time > NOW() - INTERVAL 1 HOUR ;

or

WHERE time > DATE_ADD( NOW(), INTERVAL -1 HOUR ) ;

For MS-Access:

WHERE time > DateAdd( 'h', -1, Now() ) ;


If it's MSSQL it'll be:

DateDiff(hh,time,GetDate()) < 1

Or mySQL, you'll find the altfernative here:

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_datediff


NOW() returns you a timestamp, so you can use it in following way:

SELECT some_date_related_data FROM some_table
WHERE time > ( now() - 3600 )
0

精彩评论

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

关注公众号