且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从SQL C#中的同一列的多行中减去一个值

更新时间:2022-01-17 22:42:23

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.