码迷,mamicode.com
首页 > 其他好文 > 详细

按年/月/日查询数据

时间:2016-01-25 17:12:11      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

今天:
Select * From log Where to_days(cdate) = to_days(now());


昨天:
Select * From log Where to_days( NOW( ) ) - to_days(cdate) <= 1


近7天:
Select * From log Where date_sub(CURDATE(), Interval 7 DAY) <= date(cdate)


近30天:
Select * From log Where date_sub(CURDATE(), Interval 30 DAY) <= date(cdate)


本月:
Select * From log Where date_format(cdate, %Y%m ) = date_format( CURDATE( ) , %Y%m )


本周:
Select * From log Where month(cdate) = month(curdate()) and week(cdate) = week(curdate())


上月:
Select * From log Where period_diff( date_format( now( ),%Y%m ) , date_format(cdate,%Y%m ) ) =1


今年:
Select * From log Where year( from_unixtime( cdate ) ) = year( curdate() )


本季度:
Select * From log Where quarter( from_unixtime( cdate ) ) = quarter( curdate( )) 

 

按年/月/日查询数据

标签:

原文地址:http://www.cnblogs.com/heyahui/p/5157762.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!