MySql update field value based on other field values -


im trying create query following:

here table:

id     total     paid     own       status ------------------------------------------------ 1      100.00    100.00   100.00    0 

and here query:

$total = 50; update cart table set paid = $total, status = case when $total >= own 1 else 2 end; 

the idea if total amount of field "total" equal or greater amount in field "own" update field "status" 1, otherwize 2.

im not sure if can 1 query, or need update cart table, pull results, perform calculations , update again.

try this:

update cart table set paid = $total, status = if($total >= own, 1, 2) id = 1; 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -