举个例子:
NO NAME NUM
1 AA 10
2 BB 20
1 CC 30
得到的正确结果为
NO NAME sum(NUM)
1 AA 40
2 BB 20
或者
NO NAME sum(NUM)
1 CC 40
2 BB 20
NO NAME NUM
1 AA 10
2 BB 20
1 CC 30
得到的正确结果为
NO NAME sum(NUM)
1 AA 40
2 BB 20
或者
NO NAME sum(NUM)
1 CC 40
2 BB 20
解决方案 »
- 关于between and 语句的问题
- 请教一函数!
- 如何用SQL語句在表中添加字段?
- 求详细解释。
- sql查询中字符串含有特殊字符导致查询结果不正确。。求解
- 两个无任何关系的表联查问题,T-Sql高人见来看看
- sql连接错误的问题
- 请问在sql server2000中建立数据库有什么要注意的,建立表空间的大小有什么技巧
- 关于触发器
- sql里面data文件夹有备份需要设置恢复数据,付现金酬劳
- 怎么把图片(bmp或jpg)ACCESS数据库(access97)!!!急急急!!!!!!!!!!!
- 在“英文LINUX6。1+英文ORACLE8。1。6”环境下,是否能在数据库中录入“中文“记录,并能在网页上正确显示汉字!
create table #temp(no int ,name char(10)) --创建一临时表
declare temptable cursor for --用游标向临时表写数据
select distinct no,name from yourtable
open temptable fetch from temptable into @no,@name
while @@fetch_status=0
begin
if not exists select * from #temp where no=@no
begin
insert into #temp (no,name) values(@no,@name)
end
fetch from outwardoperation into @no,@name
end
close temptable
select a.No,b.name,a.tatal
from (select no,tatal=sum(num) from yourtable group by No) a,#temp b
where a.no=b.no
from Person v1
group by v1.no
thank's very much!
from (select no,sum(num) as sum from person group by no) as a
inner join person as b
on a.no=b.no
凑个热闹。呵呵