如果我更改特定序列号的值值,如何更新表的总和。 [英] how to update the sum of a table if i change the value value of a particular serial no.

查看:74
本文介绍了如果我更改特定序列号的值值,如何更新表的总和。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,

i有4个coloums,如:(序列号,接收,发送,余额)



序列号received_item send_item余额

1 5

2 5 0 10

3 20 0 30

4 10 5 35

5 0 3 32

6 10 2 40



这里收到的物品在余额中添加并发送物品减去余额并且余额被添加到下一个收到的项目并发送从余额中扣除的项目等等....



现在如果我想要收到的序列号的更新值。 3

比25替代20然后总数增加5在所有地方的平衡coloumn序列号后。 3





更新后: -



序列号received_item send_item余额

1 5

2 5 0 10

>更新这里3 25 0 35

4 10 5 40

5 0 3 37

6 10 2 45



我应该为此做些什么..





回复plzzzz

解决方案

你不需要保持表中的余额值。无论何时获取数据,都可以计算余额。使用以下查询。



SELECT

sernum,

收到,

发送,

(从库存s2中选择总和(收到)-sum(发送),其中s2.sernum< = s1.sernum)AS余额
FROM Stock AS s1;

dear sir,
i have 4 coloums like :(serial No. , received, send, balance)

serial No. received_item send_item balance
1 5
2 5 0 10
3 20 0 30
4 10 5 35
5 0 3 32
6 10 2 40

here received item added in balance and send items minus from balance and balance is added next received item and send items subtracted from balance and so on....

now if i want update value of received items of serial no. 3
like 25 in place of 20 then total increase by 5 at all place of balance coloumn after serial no. 3


AFTER updatation:-

serial No. received_item send_item balance
1 5
2 5 0 10
>Update here 3 25 0 35
4 10 5 40
5 0 3 37
6 10 2 45

what should i do for this..


reply plzzzz

解决方案

You don''t need to keep balance values in the table. Balance can be calculated whenever you fetch the data. Use the following query.

SELECT
sernum,
received,
send,
(select sum(received)-sum(send) from stock s2 where s2.sernum<=s1.sernum) AS Balance
FROM Stock AS s1;


这篇关于如果我更改特定序列号的值值,如何更新表的总和。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆