| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 552 人关注过本帖
标题:关于一个表的连接怎么实现?
只看楼主 加入收藏
fhqwfn
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-4-9
收藏
 问题点数:0 回复次数:1 
关于一个表的连接怎么实现?

表cwsf
dybh nd yf je
1-1-1 2006 2 30
1-1-1 2006 3 60
1-1-1 2006 4 80
1-1-2 2006 2 20
1-1-2 2006 3 70
。。。。。
我想实现:
1-1-1结果为2月的费用为30,3月份的费用为30,4月份的费用为20
1-1-2结果为2月的费用为20,3月份的费用为50
以2月份为标准,以后每个月的费用为该月费用减去前月费用。

update cwsf set je=tt.je-a.je from (select dybh,sum(je) from cwsf where nd=2006 and yf=3 group dybh) tt,
(select dybh,sum(je) from cwsf where nd=2006 and yf=2 group dybh) a
where nd=2006 and yf=3

可以一个月一个月的实现,或者用其它方法.不过现在错误的.
请教下应该怎么样实现先谢过了....

搜索更多相关主题的帖子: update where 
2006-04-09 11:54
jiweida
Rank: 1
等 级:新手上路
帖 子:45
专家分:0
注 册:2006-4-9
收藏
得分:0 
回复:(fhqwfn)关于一个表的连接怎么实现?
update cwfs set je=(select isnull(je-(select top 1 je from cwfs where yf=a.yf-1 and dybh=a.dybh and nd=a.nd),je )) from cwfs a

真便宜呀真便宜真便宜呀真便宜。。。。。。。
2006-04-09 20:06
快速回复:关于一个表的连接怎么实现?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013051 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved