![](/img/trans.png)
[英]SQLite: How can I update a column with a value that is the difference between two rows of another column?
[英]How can I update a column (multiple rows) in a table with the lower value between 2 column in 2 tables?
我需要比较卖方的裁定额与产品的裁定额,并将较低的值详细地输入到裁定额栏中。
table 1: details doc comision seller product 1 0 001 0101 1 0 001 0315 1 0 001 0425 2 0 001 0389 2 0 001 0315 table 2: products code description comision 0101 product 1 5 0315 product 2 7 0425 product 3 3 0389 product 4 8 . . . table 3: sellers code name comision 001 seller 1 6 002 seller 2 3 . . .
我这样做:
declare @comisionVendedor float,@comisionProducto float, @comision float,@prod='0101'
set @comisionVendedor=0
set @comisionProducto=0
select @comisionVendedor=comision from vendedor join details on seller.CODe=details.seller where details.doc=1 and prod=@prod
select @comisionProducto=products.COMISION from products join details on products.CODe=details.PRODuct where details.doc=1 and prod=@prod
if @comisionVendedor>@comisionProducto begin set @comision=@comisionProducto end
else begin set @comision=@comisionVendedor end
update details set comision=@comision where details.doc=1 and product=@prod
它工作正常,但仅适用于一种产品。 如何用文档号1替换3行的comision列?
您可以使用printf命令
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.