SQLServer的本月统计和本周统计

本月统计(MySQL)
select * from booking where month(booking_time) = month(curdate()) and year(booking_time) = year(curdate())

本周统计(MySQL)
select * from spf_booking where month(booking_time) = month(curdate()) and week(booking_time) = week(curdate())

 

[SQLServer]
表名为:tableName
时间字段名为:theDate

查询本月的记录
select * from tableName where DATEPART(mm, theDate) = DATEPART(mm, GETDATE()) and DATEPART(yy, theDate) = DATEPART(yy, GETDATE())

查询本周的记录
select * from tableName where DATEPART(wk, theDate) = DATEPART(wk, GETDATE()) and DATEPART(yy, theDate) = DATEPART(yy, GETDATE())

查询本季的记录
select * from tableName where DATEPART(qq, theDate) = DATEPART(qq, GETDATE()) and DATEPART(yy, theDate) = DATEPART(yy, GETDATE())

其中:GETDATE()是获得系统时间的函数。

posted on 2012-12-29 17:54  szqizh  阅读(224)  评论(0编辑  收藏  举报

导航