简体   繁体   中英

Variables/For Each in SQL

So I know I should have checked this before inserting but I did a sql insert that inserted the wrong date on several rows. The formula to correct this would be

accounts.timely_date = accounts.due_date + 45 days where accounts.facility_id = 44 .

Is there any way to do this in sql for multiple rows at once?

You can use an UPDATE query:

update accounts
set
  timely_date = due_date + interval 45 day
where
  facility_id = 44

This SQL statement will update all rows in accounts table where facility_id = 44

update accounts
set timely_date = DATE_ADD(due_date,INTERVAL 45 DAY)
where facility_id = 44

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