如何从SQL C#中的同一列的多行中减去一个值 [英] How to subtract one value from multiple rows of same column in SQL C#

查看:121
本文介绍了如何从SQL C#中的同一列的多行中减去一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从数据栏日期减去40公斤米饭,如第1排10和第2排25等等



i want to subtract 40kg rice from qty column date wise like from 1st row 10 and 2ed row 25 and so on

ing_id|qty|Price|Date       |unit |name
01    |10|50    |12/12/2018 |kg   |Rice
01    |25|56    |12/14/2018 |kg   |Rice
01    |30|70    |12/20/2018 |kg   |Rice





并更新表格如下:





and update the table like :

ing_id|qty|Price|Date       |unit |name
01    |00|50    |12/12/2018 |kg   |Rice
01    |00|56    |12/14/2018 |kg   |Rice
01    |15|70    |12/20/2018 |kg   |Rice









hepl !!在此先感谢



我尝试过的事情:



我不会动摇该怎么做!

任何建议

或帮助





hepl!! Thanks in Advance

What I have tried:

I dont undarstand how to do!
any suggestion
or help

推荐答案

Afzaal Ahmad Zeeshan是连接,我是害怕。



在SQL中,只有当每行的命令相同时,才能更改为多行!因此,对特定行应用不同的减法,你必须为每个减法定义一个特定的命令。



唯一的例外是你可以定义一个使用的一般方程式表数据作为输入 - 例如通过使用子选择获取要减去的平均值,然后使用它来将计算值应用于每一行。但是为此,我担心你没有提供足够的信息来找到这样的方式。
Afzaal Ahmad Zeeshan is connect, I'm afraid.

In SQL you can aplly changes to multible rows only if the command is the same for every row! Thus applying different substractions for specific rows you'll have to define a specific command for each substraction.

The only exception would be if you could define a general equation which uses the table data as input - e.g. by using a sub-select getting the average value to subtract and then using that to apply a calculated value to each row. But for that I'm afraid you didn't give enough information to find such a way.


实际上,第二个表中的第3个数量应该是25个,而不是15个40kg问题对比五十公斤如果这将是一个持续的事情,创建一个存储过程来遍历给定sku,qty的行集,并对可用的over / under qty进行一些错误处理..或者只是弄清楚存储过程并在VS /中对其进行编码C#级别。这是一个很酷的要求,像往常一样,必要性是发明的母亲。需要存储过程。 ,让我知道。
actually, 3rd qty in the 2nd table should be 25 instead of 15 for the 40kg question versus 50kg. if this is going to be an ongoing thing, create a stored procedure to walk through the rowset given sku, qty, with some error handling for over/under qty available.. or just figure out the stored procedure and code it at the VS/C# level. that's a cool request, as usual, necessity is the mother of invention. need the stored procedure. , let me know.


这篇关于如何从SQL C#中的同一列的多行中减去一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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