如何统计一段时间内重复记录,并显示。
数据库中的记录如下
字段名 时间
title dateandtime
BBC 2007-7-26 10:08:46
BBA 2007-7-26 10:08:45
BBC 2007-7-26 10:08:44
BBD 2007-7-26 10:08:44
BBA 2007-7-26 10:08:44
BBC 2007-7-26 10:08:44
BBA 2007-7-26 10:08:44
BBA 2007-7-26 10:08:44
一周内根据记录出现的次数统计显示
字段名 次数
title hits
BBA 4
BBC 3
BBD 1
[解决办法]
select title,count(*) as hits
from 表
group by title
order by title
[解决办法]
好不容易找着个会的,还被楼上的抢了,55555
[解决办法]
select title, hits = count(1)
from 表
where datediff(wk, dateandtime, getdate()) = 0
group by title
[解决办法]
select title,count(1) as hits
from 表名
group by title
order by hits desc
[解决办法]
select title,count(title) as hits
from 表名
group by title
order by hits desc