简体   繁体   中英

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.

The table name is 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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