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

SQLServer 查询 本周 本月的记录

发布时间:2020-12-12 15:11:54 所属栏目:MsSql教程 来源:网络整理
导读:[SQLServer] 表名为:tableName 时间字段名为:theDate 查询本月的记录 select * from tableName where DATEPART(mm,theDate) = DATEPART(mm,GETDATE()) and DATEPART(yy,theDate) = DATEPART(yy,GETDATE()) 查询本周的记录 select * from tableName where D

[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()是获得系统时间的函数。

统计表里字段datetime每周录入的行数:

select distinct datename(week,datetime),count(*) from messagegs
where? substring(serviceid,3,4)='GS' and datetime>'20090101'
group by datename(week,datetime)

统计表里时间字段datetiem每小时的行数,得出话务忙时间段:

select distinct datename(hh,count(*) from messagegs where? substring(serviceid,4)='GS' --and datetime>'20090101' group by datename(hh,datetime)

(编辑:李大同)

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

    推荐文章
      热点阅读