首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

怎么根据当前时间查询3个月以内的表中内容

2012-08-08 
如何根据当前时间查询3个月以内的表中内容例如某张表有时间字段 addTime别的都是一些基本字段,那么怎么根

如何根据当前时间查询3个月以内的表中内容
例如某张表有时间字段 addTime 别的都是一些基本字段,那么怎么根据这个时间来写查询呢!查询3个月内 和 3个月外 的表信息。谢谢啦

[解决办法]

SQL code
select * from tb where datediff(mm,addtime,getdate())<=3 ---3个月内select * from tb where datediff(mm,addtime,getdate())>3   --3个月外
[解决办法]
SQL code
select * from tb where datediff(mm,addtime,getdate())<=3 ---3个月内orselect * from tb where datediff(mm,addtime,getdate())>3   --3个月外
[解决办法]
select * from tb where datediff(mm,addtime,getdate())<=3 ---3个月内

select * from tb where datediff(mm,addtime,getdate())>3 --3个月外

[解决办法]
SQL code
select * from tb where dateadd(mm,3,addtime)>=getdate() ---3个月内select * from tb where dateadd(mm,3,addtime)<getdate()   --3个月外 

热点排行