select
top 1 a.*
from
(select
UserID,Visit=sum(Visit)
from
表
group by
UserID,convert(char(7),[Datetime],120)) a
order by
a.Visit
top 1 a.*
from
(select
UserID,Visit=sum(Visit)
from
表
group by
UserID,convert(char(7),[Datetime],120)) a
order by
a.Visit
top 1 a.*
from
(select
UserID,Visit=sum(Visit)
from
表
group by
UserID,convert(char(7),[Datetime],120)) a
order by
a.Visit desc
select '2','2005-10-10',34 union all
select '2','2005-10-10',222 union all
select '7','2005-11-10', 348 union all
select '2','2005-11-11', 34 union all
select '7','2005-11-12', 344 union all
select '3','2005-11-12', 35 union all
select '3','2005-11-15', 34
select top 1 t.userid from (select userid,sum(visit) as visit from #t group by userid) t order by t.visit desc
from 表
group by userid,month(datetime)
order by visit desc
select top 1 t.userid,t.visit from (select userid,sum(visit) as visit from #t group by userid,month([datetime])) t order by t.visit desc
insert into @a select 1,2,'2005-10-10',34
insert into @a select 2,2,'2005-10-10',222
insert into @a select 3,7,'2005-11-10',348
insert into @a select 4,2,'2005-11-11',34
insert into @a select 5,7,'2005-11-12',344
insert into @a select 6,3,'2005-11-12',35
insert into @a select 7,3,'2005-11-15',34
select top 1 a.userid,ab.aa,sum(visit)visit from @a a,(
select id,month(datetime)as aa from @a)ab
where a.id=ab.id
group by a.userid,ab.aa
order by visit desc