加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

SQLServer的本月统计和本周统计

发布时间:2020-12-12 14:06:55 所属栏目:MsSql教程 来源:网络整理
导读: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()

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())

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

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

? ? ? 转自? http://hi.baidu.com/zhonghefu/item/290b7a0bdf912d1aeafe3885

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读