就是一个竞猜系统 表的字段有 id ,UserId,Odds, 我想把Odds的和算出来,然后把每条记录竞猜的Odds取出来,并且只执行一个SQL语句
declare @t table ( id int identity(1,1), UserId varchar(10), Odds int )insert @t select 'a',12 union all select 'b',23 union all select 'c',34 select isnull(userid,'total') as userid, sum(odds) as odds from @t group by userid with rollup/** userid odds -------------- a 12 b 23 c 34 total 69 **/
select sum(Odds) from 表 union all select Odds from 表
表的字段有 id ,UserId,Odds,
我想把Odds的和算出来,然后把每条记录竞猜的Odds取出来,并且只执行一个SQL语句
declare @t table
(
id int identity(1,1),
UserId varchar(10),
Odds int
)insert @t select 'a',12
union all select 'b',23
union all select 'c',34
select
isnull(userid,'total') as userid,
sum(odds) as odds
from @t
group by userid
with rollup/**
userid odds
--------------
a 12
b 23
c 34
total 69
**/