按年/月/日查询数据
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了按年/月/日查询数据相关的知识,希望对你有一定的参考价值。
今天: 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( ))
以上是关于按年/月/日查询数据的主要内容,如果未能解决你的问题,请参考以下文章
如何将数据从按年/月/日分区的存储桶中加载到 bigquery