首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

怎么统计一段时间内重复记录,并显示

2012-01-05 
如何统计一段时间内重复记录,并显示。数据库中的记录如下字段名时间titledateandtimeBBC2007-7-2610:08:46B

如何统计一段时间内重复记录,并显示。
数据库中的记录如下

字段名     时间
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

热点排行
Bad Request.