22,206
社区成员
发帖
与我相关
我的任务
分享
select sum(col) '总和' from
(
select top 3 * from #tb
) T
create table #TB(id int, col int)
insert #TB
select 1, 100 union all
select 2, 100 union all
select 3, 100 union all
select 4, 100 union all
select 5, 100
select id,sum(col) from
(
select top 3 * from #tb
) T
group by id
declare @tb table(id int, col int)
insert @tb
select 1, 100 union all
select 2, 100 union all
select 3, 100 union all
select 4, 100 union all
select 5, 100
set rowcount 3
declare @total int
set @total=0
select @total=@total+col from @tb
select @total as total
set rowcount 0
/*
total
-----------
300
*/
select top 3 sum(col) scol from tb order by col
select sum(col) from (
select top3 col from tableName ) a