日期:2014-05-19  浏览次数:20696 次

求一过滤时间后的数据?
如表(TalbeA):
id         title     addtime
1           abc         2006-2-3
.
.
.
需要求取七条数据:
从addtime今日的数据取七条,如果不足则取昨日数据,否则还不足则取过去2日,依次类推,一定要补足七条数据。
谢谢!


------解决方案--------------------
--try

select top 7 * from TalbeA
where addtime <=getdate()
order by addtime desc


------解决方案--------------------
select * from TalbeA
where addtime in(select top 7 addtime from TalbeA order by addtime desc)
------解决方案--------------------
select top 7 * from TalbeA
where addtime <convert(char(10),getdate()+1,102)
order by addtime desc