如何统计一天内的有效回复

WBOY
Release: 2016-06-13 10:03:24
Original
885 people have browsed it

怎么统计一天内的有效回复
有一个回复表

有字段
作者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 code
SELECT *,count(DISTINCT(发贴时间的前8位)) AS times FROM table GROUP BY id<br><font color="#e78608">------解决方案--------------------</font><br>SELECT 作者id, 发贴时间<br>FROM table a<br>WHERE (NOT EXISTS<br>     (SELECT 作者id<br>     FROM table b<br>     WHERE b.作者id = a.作者id AND b.发贴时间 > a.发贴时间))<br>ORDER BY 作者id, 发贴时间 DESC<br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
SQL code
declare @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<br><font color="#e78608">------解决方案--------------------</font><br>select count(ID) as cnt,ID from table where str_date="xxxx-xx-xx" group by ID order by cnt<br><font color="#e78608">------解决方案--------------------</font><br>SELECT   作者id,   发贴时间  <br>FROM   table   a  <br>WHERE   (NOT   EXISTS  <br>     (SELECT   作者id  <br>       FROM   table   b  <br>       WHERE   b.作者id   =   a.作者id   AND   b.发贴时间   >   a.发贴时间))  <br>ORDER   BY   作者id,   发贴时间   DESC<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template