简体   繁体   English

根据同一表中的行更新值

[英]Update value based on row within the same table

Good Afternoon, 下午好,

I have an issue where I need to reference a row within the same table to update a value for a row within the same table. 我有一个问题,我需要引用同一张表中的一行以更新同一张表中的一行的值。 For example 例如

id       |  pro_id | field_id | value_decimal   
14012    |  3748   | 127      | 700.00  
14011    |  3748   | 128      | **UPDATE THIS VALUE**

I need to set the value_decimal for field_id 128 to value decimal of field_id 127/4.33 and then rounded up. 我需要将field_id 128的value_decimal设置为field_id 127 / 4.33的十进制值,然后将其四舍五入。

The table name is polaracc_osrs_property_field_value 表名称为polaracc_osrs_property_field_value

I have been banging my head against a brick wall all morning :-( 我整个早晨都在撞砖墙。

Thanks for all of the suggestions I was able to solve this with the below using the method suggested in another forum post. 感谢所有建议,我可以使用另一篇论坛文章中建议的方法通过以下方法解决此问题。

UPDATE polaracc_osrs_property_field_value t, (SELECT ID, pro_id, field_id, value_decimal FROM polaracc_osrs_property_field_value WHERE field_id = 128) t1 SET t.value_decimal = round(t1.value_decimal/4.33) WHERE t.pro_id = t1.pro_id AND t.field_id = 126; 更新polaracc_osrs_property_field_value t,(SELECT ID,pro_id,field_id,value_decimal from polaracc_osrs_property_field_value WHERE field_id = 128)t1 SET t.value_decimal = round(t1.value_decimal / 4.33)WHERE t.pro_id = t1.pro_id AND t。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM