# 找出本年注册用户最多的一天解决办法

www.MyException.Cn  网友分享于：2013-04-10  浏览：16次

------解决方案--------------------
create table T(Name varchar(10), regDate datetime)
insert T select 'AA ', '2006-12-01 '
insert T select 'BB ', '2006-12-02 '
insert T select 'CC ', '2007-01-01 '
insert T select 'DD ', '2007-01-02 '
insert T select 'EE ', '2007-01-02 '

select top 1 regDate=convert(char(10), regDate, 120), [count]=count(*) from T
where year(regDate)=year(getdate())
group by convert(char(10), regDate, 120)
order by 2 desc

--result
regDate count
---------- -----------
2007-01-02 2

(1 row(s) affected)
------解决方案--------------------

select * from
(
select (convert(varchar(10),recordDate,120))as 'day ',count(*)as 'cont ' from s2
where year(recordDate)=year(getdate())
group by (convert(varchar(10),recordDate,120))
)as aa
where aa.cont=(select max(cont)from (
select (convert(varchar(10),recordDate,120))as 'day ',count(*)as 'cont ' from s2
where year(recordDate)=year(getdate())
group by (convert(varchar(10),recordDate,120))
)as bb)
------解决方案--------------------

------解决方案--------------------

select top 1 regDate=convert(char(10), regDate, 120), [count]=count(*) from T
where year(regDate)=year(getdate())
group by convert(char(10), regDate, 120)
order by 2 desc
~~

------解决方案--------------------
select top 1 recorddate,count(1)
from table1 group by recorddate order by count(1) desc

------解决方案--------------------
select*from 记录注册用户的表 where 记录注册人数的字段=(select max(记录注册人数的字段) from 记录注册用户的表 where year(时间字段)=年 ) and year(时间字段)=年
------解决方案--------------------
create table T(Name varchar(10), regDate datetime)
insert T select 'AA ', '2006-12-01 '
insert T select 'BB ', '2006-12-02 '
insert T select 'CC ', '2007-01-01 '
insert T select 'DD ', '2007-01-01 '
insert T select 'EE ', '2007-01-02 '
insert T select 'FF ', '2007-01-03 '
insert T select 'GG ', '2007-01-03 '

select top 1 with ties regDate=convert(char(10), regDate, 120), [count]=count(*) from T
where year(regDate)=year(getdate())
group by convert(char(10), regDate, 120)
order by 2 desc

--result
regDate count
---------- -----------
2007-01-01 2
2007-01-03 2

(2 row(s) affected)
------解决方案--------------------
select top 1 用戶， count(*) as total from t group by left([time],8) order by total desc

------解决方案--------------------
select max(d.c) from (
select count(date(regDate)) as c from datatable group by date(regDate))d
------解决方案--------------------

select top 1 * from