请教一个SQL语句求和问题!

[复制链接]
查看11 | 回复4 | 2011-10-27 22:40:39 | 显示全部楼层 |阅读模式
设你的这些数据存在 #a中alter table #a add sid int identity (1,1)----增加一列 sid 作为行编号godeclare @num int ----和declare @sid int ----编号set @num=0set @sid=1while @sid<4beginselect @num=@num+value1+value2+value3 from #awhere sid=@sidset @sid=@sid+1endselect @num ----循环结束,输出结果==================================这是我的理解...
回复

使用道具 举报

千问 | 2011-10-27 22:40:39 | 显示全部楼层
多字段求和什么意思呢?是下面的1还是2呢?1.select sum(a b c) into 变量名 from 表名;2.select sum(a) into 变量1,sum(b) into 变量2 from 表名...
回复

使用道具 举报

千问 | 2011-10-27 22:40:39 | 显示全部楼层
正确答案:经过测试后可用select sum(VALUE1),sum(VALUE2),sum(VALUE3) from (select t.*from VALUE t where rownum <4) e;还有问题Hi我!...
回复

使用道具 举报

千问 | 2011-10-27 22:40:39 | 显示全部楼层
declare @a intdeclare @b intdeclare @c intdeclare @result intselect @a=sum(value1),@b=sum(value2),@c=sum(value3) from (select top 3 * from 表名) as temptableselect @result=...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行