错了,结果应为
xm zhi lj
-------------
a 5 9
b 0 2
c 0 4
xm zhi lj
-------------
a 5 9
b 0 2
c 0 4
解决方案 »
- 把 Excel 当作 Jet Engine 的外部数据库,用 SQL 语句从 Access 或 SQL 数据库直接导入记录集。
- 超简单(送分题)
- 求一个计算平均值的类模块的算法
- 好烦的问题
- 急急急急
- VB.NET一个项目的EXCEL错误!请高手解决!!!
- 两个动态IP,一个静态IP,如何编程实现通过静态IP的机器进行两个动态IP机器间的数据转发?
- 在string中如何标识换行付,,???
- 如何得到当前使用数据库的用户名和机器名
- 从高中生到CEO,看一个程序员的成长经历
- ActiveX控件中的WEBBROWSER控件编辑WORD文档时可否不在客户端生成临时文件?
- 两个byte型数组,如何将它们合并为一个?
支持飞雨的
支持楼上
xm zhi lj
a 5 9可是b,c的值呢?应形成如下所示:
xm zhi lj
-------------
a 5 9
b 0 2
c 0 4
from (
selec distinct xm from table) a
left join
(select xm,zhi from table where id='20030') b on a.xm=b.xm
left join (select xm,sum(zhi) as lj where id<'20030' group by xm) c
on a.xm=c.xm
create proc User_Print
as
declare @xm varchar(2),@zhi int,@lj int
declare cur_tbl cursor for
select a.xm,a.zhi,b.lj from (select xm,max(zhi) as zhi from tbl where id ='200303' group by xm) a left join (select xm,sum(zhi) as lj from tbl where id <='200303' group by xm) b on a.xm =b.xm
open cur_tbl
fetch next from cur_tbl into @xm,@zhi,@lj
while (@@fetch_status<>-1)
begin
print @xm
fetch next from cur_tbl into @xm,@zhi,@lj
end
close cur_tbl
deallocate cur_tbl
select a.xm,a.zhi,b.lj from (select xm,max(zhi) as zhi from tbl where id ='200303' group by xm) a left join (select xm,sum(zhi) as lj from tbl where id <='200303' group by xm) b on a.xm =b.xm
declare cur_table cursor for
select a.xm,a.zhi,b.lj from (select xm,max(zhi)as zhi from tbl where xm <> @xm group by xm) a left join (select xm,sum(zhi) as lj from tbl where xm <> @xm group by xm ) b on a.xm=b.xm
open cur_table
fetch next from cur_table into @xm,@zhi,@lj
if (@zhi=@lj)
begin
set @zhi=0
select @xm,@zhi,@lj
end
while(@@fetch_status <>-1)
begin
fetch next from cur_table into @xm,@zhi,@lj
if (@zhi=@lj)
begin
set @zhi=0
select @xm,@zhi,@lj
end
end
close cur_table
deallocate cur_table
select a.xm,isnull(b.zhi,0) as zhi,c.lj
from
(select distinct xm from ttt) a
left join
(select xm,zhi from ttt where id='200303') b on a.xm=b.xm
left join
(select xm,sum(zhi) as lj from ttt group by xm) c on a.xm=c.xm 谢谢楼上的朋友们!