查询某日期区间的数据

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
————————————————
版权声明:本文为CSDN博主「smartsmile2012」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/smartsmile2012/article/details/93976959

猜你喜欢

转载自www.cnblogs.com/Anthony518/p/11456755.html