怎么统计一天内的有效回复
有一个回复表
有字段
作者id,发贴时间
11 08-01-01 15:00
12 08-01-01 16:00
13 08-01-01 17:00
12 08-01-01 18:00
12 08-01-02 16:00
我现在要统计有效回复
24小时内同一个人的回复算是一次有效回复
计算回复数是
11 (1次)
12 (2次)其中有一次是24小时内回复的所以剔除
13 (1次)
有没有比较好的算法提供,我先存到数组,通过不断遍历数组来比较,感觉太烦琐
谢谢大虾们
------解决方案--------------------
24小时有效一次,你都规定是1次了,还统计什么???
要么用时间去做减法(order by 发帖时间,用top2把最后两个值取出一比就完了呗,没事搞什么遍历),要么有回复就锁24小时id
------解决方案--------------------
sql codeselect *,count(distinct(发贴时间的前8位)) as times from table group by id
------解决方案--------------------
select 作者id, 发贴时间
from table a
where (not exists
(select 作者id
from table b
where b.作者id = a.作者id and b.发贴时间 > a.发贴时间))
order by 作者id, 发贴时间 desc
------解决方案--------------------
sql codedeclare @t table([作者id] int ,[发贴时间] datetime)insert into @t select 11,'08-01-01 15:00 ' union select 12,'08-01-01 16:00 ' union select 13,'08-01-01 17:00 ' union select 12,'08-01-01 18:00 ' union select 12,'08-01-02 16:00 ' select id,count(*)as [发贴次数] from (select [作者id] as id from @t group by [作者id],convert (varchar(10),[发贴时间],120)) t group by t.id
------解决方案--------------------
select count(id) as cnt,id from table where str_date=xxxx-xx-xx group by id order by cnt
------解决方案--------------------
select 作者id, 发贴时间
from table a
where (not exists
(select 作者id
from table b
where b.作者id = a.作者id and b.发贴时间 > a.发贴时间))
order by 作者id, 发贴时间 desc