select top 1 count(1) from t where datepart(d,datecol) = 12 group by convert(char(10),datecol,120) order by count(1) desc
select top 1 日期=convert(char(10),datecol,120), 添加的记录数=count(1) from t where datepart(mm,datecol) = 12 group by convert(char(10),datecol,120) order by 添加的记录数 desc
select top 1 convert(char(10),datecol,120), count(1) from t where datepart(m,datecol) = 12 group by convert(char(10),datecol,120) order by count(1) desc
[code=SQL]select datepart(dy,date),count(1) as 记录 from T where convert(varchar(7),date,120)='2007-12' group by datepart(dy,date) [/code]
datepart(dy,date)--显示当月的天数
declare @tb table (id int,col varchar(10),dt datetime) insert into @tb select 1,'a','2008-12-01' insert into @tb select 2,'a','2008-12-01' insert into @tb select 3,'a','2008-12-01' insert into @tb select 4,'a','2008-12-02' insert into @tb select 5,'a','2008-12-02' insert into @tb select 6,'a','2008-12-03' insert into @tb select 7,'a','2008-12-03' insert into @tb select 8,'a','2008-12-03' insert into @tb select 9,'a','2008-12-05' insert into @tb select 10,'a','2008-12-05' insert into @tb select 11,'a','2008-12-05' insert into @tb select 12,'a','2008-12-05'select top 1 convert(varchar(10),dt,120)as '日期',count(1) as cn from @tb where datename(mm,dt)=12 group by convert(varchar(10),dt,120) order by cn desc日期 cn 2008-12-05 4
select top 1 convert(varchar(10),时间字段,120) from 表名 where datediff(mm,时间字段,getdate())=0 group by convert(varchar(10),时间字段,120) order by count(1) desc
上面是统计本月。。 下面统计12月; select top 1 convert(varchar(10),时间字段,120) from 表名 where datepart(mm,时间字段)=12 group by convert(varchar(10),时间字段,120) order by count(1) desc
怎样统计出12月,那天添加的记录最多。select top 1 convert(varchar(10),日期,120) 日期 , count(*) cnt from tb group by convert(varchar(10),日期,120) order by cnt desc
from t
where datepart(d,datecol) = 12
group by convert(char(10),datecol,120)
order by count(1) desc
from t
where datepart(mm,datecol) = 12
group by convert(char(10),datecol,120)
order by 添加的记录数 desc
from t
where datepart(m,datecol) = 12
group by convert(char(10),datecol,120)
order by count(1) desc
from T
where convert(varchar(7),date,120)='2007-12'
group by datepart(dy,date)
[/code]
insert into @tb select 1,'a','2008-12-01'
insert into @tb select 2,'a','2008-12-01'
insert into @tb select 3,'a','2008-12-01'
insert into @tb select 4,'a','2008-12-02'
insert into @tb select 5,'a','2008-12-02'
insert into @tb select 6,'a','2008-12-03'
insert into @tb select 7,'a','2008-12-03'
insert into @tb select 8,'a','2008-12-03'
insert into @tb select 9,'a','2008-12-05'
insert into @tb select 10,'a','2008-12-05'
insert into @tb select 11,'a','2008-12-05'
insert into @tb select 12,'a','2008-12-05'select top 1 convert(varchar(10),dt,120)as '日期',count(1) as cn
from @tb where datename(mm,dt)=12
group by convert(varchar(10),dt,120)
order by cn desc日期 cn
2008-12-05 4
select top 1 convert(varchar(10),时间字段,120) from 表名
where datediff(mm,时间字段,getdate())=0 group by convert(varchar(10),时间字段,120)
order by count(1) desc
上面是统计本月。。
下面统计12月;
select top 1 convert(varchar(10),时间字段,120) from 表名
where datepart(mm,时间字段)=12 group by convert(varchar(10),时间字段,120)
order by count(1) desc