62,046
社区成员
发帖
与我相关
我的任务
分享
create table #PP
(
ID int identity(1,1) primary key,
name varchar(20),
num int,
time Datetime,
shopp_id int
)
insert into #PP select 'aa',50,'2010-03-01',1
insert into #PP select 'bb',50,'2010-02-01',2
insert into #PP select 'cc',100,'2010-03-01',1
insert into #PP select 'aa',50,'2010-03-01',1
insert into #PP select 'bb',60,'2010-03-01',1
insert into #PP select 'dd',70,'2010-02-01',2
insert into #PP select 'qq',110,'2010-03-01',2
select A.name from
(
select name,sum(num) num from
(
select * from #PP where time='2010-03-01' and shopp_id=1
) tt
group by name
) A
join
(
select max(num) num from
(
select name,sum(num) num from
(
select * from #PP where time='2010-03-01' and shopp_id=1
) tt
group by name
) tt
) B
on A.num=B.num
name
--------------------
aa
cc
(2 行受影响)