select sum(sl) from ( select distinct ID,sl from 表 where time between '2013-4-1' and '2013-4-5' )a
select SUM(s) from ( select max(sl) s from 表 where [time] Between '2013-04-01' And '2013-04-05' group by id) a
显示 ID SL 1 2 2 3
create table tab3 ( ID int,SL int,time date ) insert into tab3 select 1,1,'2013-04-01' union all select 2,2,'2013-04-02' union all select 1,1,'2013-04-03' union all select 2,1,'2013-04-04' select ID,sum(SL) SL from ( select ID,SL from tab3 ) b group by ID ID SL ----------- ----------- 1 2 2 3(2 行受影响)
select ID,sum(SL) SL from ( select ID,SL from tab3 where [time] Between '2013-04-01' And '2013-04-05' ) b group by ID
select max(id) id,sum(sl) sl from 表 where [time] Between '2013-04-01' And '2013-04-05' group by id
select id,sum(sl) sl from dbo.test1 where [time] Between '2013-04-01' And '2013-04-05' group by id
select distinct ID,sum(SL) SL from ( select ID,SL from tab3 where [time] Between '2013-04-01' And '2013-04-05' ) b group by ID
select distinct ID,sl from 表 where time between '2013-4-1' and '2013-4-5'
)a
select max(sl) s from 表 where [time] Between '2013-04-01' And '2013-04-05'
group by id) a
1 2
2 3
(
ID int,SL int,time date
)
insert into tab3
select 1,1,'2013-04-01' union all
select 2,2,'2013-04-02' union all
select 1,1,'2013-04-03' union all
select 2,1,'2013-04-04' select ID,sum(SL) SL from (
select ID,SL
from tab3
) b group by ID
ID SL
----------- -----------
1 2
2 3(2 行受影响)
select ID,SL
from tab3 where [time] Between '2013-04-01' And '2013-04-05'
) b group by ID
group by id
group by id
from
(
select ID,SL
from tab3
where [time] Between '2013-04-01' And '2013-04-05'
) b
group by ID