日期:2014-05-17  浏览次数:20505 次

有算法达人吗
其实这个问题不算算法问题吧

 这两天也一直在思考这个怎么解决,但一直没想出来

要求是这样的

比如数据库数据有   1,2,3,4,5,6,7,8,9,10,11,12

那么今天    我要显示的数据是 1,2,3,4
明天        我要显示的数据是 3,4,5,6
后天        我要显示的数据是 5,6,7,8
意思相信大家都看明白了  就是每天的数据,前面一半是昨天的,后面一半是今天的
具体实现应该怎么实现呢

缓存?
日期?

达人帮下啊




------最佳解决方案--------------------
declare @times datetime
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
------其他解决方案--------------------
这个肯定要弄你今天的这个日期的,

然后绑定数据的时候和你存的'今天'的日期做比较,这一天的数据条数为天数差*2+1,天数差*2+2,天数差*2+3,天数差*2+4 ,

不知道这个是你要的意思不?
------其他解决方案--------------------
存一个节点, 第一天是0 第二天是2 第三天是4
------其他解决方案--------------------
感觉加一天显示的就会加二
能不能用个时间做判断呢
新手啊!一点小小的想法,多多包涵
------其他解决方案--------------------
这个要感谢3楼的兄弟 提出来的
虽然具体怎么实现,我还不知道,但至少有一个思路了
我现在在考虑的是如果数据都读取过了,要如何重头再来
------其他解决方案--------------------
select top 4 * from source where rowindex>(day(getdate()-@times)*2-2)%(select count(1) 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
------其他解决方案--------------------
引用:
select top 4 * from source where rowindex>(day(getdate()-@times)*2-2)%(select count(1) from source)
union all
select top (case when(4-(select count(1) from source where rowindex>day(getdate()-@times……

同意!