微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SQLServer 查询 本周 本月的记录

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐