其实这个问题不算算法问题吧 这两天也一直在思考这个怎么解决,但一直没想出来要求是这样的比如数据库数据有 1,2,3,4,5,6,7,8,9,10,11,12那么今天 我要显示的数据是 1,2,3,4
明天 我要显示的数据是 3,4,5,6
后天 我要显示的数据是 5,6,7,8
意思相信大家都看明白了 就是每天的数据,前面一半是昨天的,后面一半是今天的
具体实现应该怎么实现呢缓存?
日期?达人帮下啊
明天 我要显示的数据是 3,4,5,6
后天 我要显示的数据是 5,6,7,8
意思相信大家都看明白了 就是每天的数据,前面一半是昨天的,后面一半是今天的
具体实现应该怎么实现呢缓存?
日期?达人帮下啊
set @times='2012-11-22'
;with tb(id)
as(
select 1 union all
select 2 union all
select 3 union all
select 4 union all
select 5 union all
select 6 union all
select 7 union all
select 8 union all
select 9 union all
select 10 union all
select 11 union all
select 12
),
source as(
select id,rowindex=row_number()over(order by id) from tb)
select top 4 * from source where rowindex>(day(getdate()-@times)*2-2)%(select count(1) from source)
union all
select top (4-(select count(1) from source where rowindex>day(getdate()-@times)*2-2)) * from source
union all
select top (case when(4-(select count(1) from source where rowindex>day(getdate()-@times)*2-2))<0 then 0 else
4-(select count(1) from source where rowindex>day(getdate()-@times)*2-2) end
) * from source