Sql Server 查询指定范围(一周,一月,本周,本月等)内的数据


1.查询今日的所有数据

select * from 表名 where datediff(day,字段名,getdate())=0

2.查询昨日的所有数据

select * from 表名 where datediff(day,字段名,getdate()-1)=0

3.查询当天日期在一周年的数据

selcet * from 表名 where datediff(week,字段名,getdate()-1)=0

4.查询前30天的数据

select * from 表名 where datediff(d,字段名,getdate())<=30

5.查询上一个月的数据

select * from 表名 where datediff(m,字段名,getdate())<=1

6.查询当天的数据

select * from 表名 where datediff(dd,字段名,getdate())=0

7.查询24小时内的数据

select * from 表名 where datediff(hh,字段名,getdate())

8.查询本周的数据

select * from 表名 where datediff(week,字段名,getdate())=0

9.查询本月的数据

select * from 表名 where datediff(month,字段名,getdate())=0

10.查询本季的数据

select * from 表名 where datediff(qq,字段名,getdate())=0


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM