简体   繁体   中英

Drupal how to use a sql case statement alike

I need to update all the nodes in the database based on a certain condition, and I need this update to be conditional. If a certain field is equal to a value, what the modified value will be X If it is otherwise, the value will be y, in a more accurate sense, I need something similar to the case statement in the sql.

Update [node]
Set    [field] = CASE WHEN [field] IN (value1, value2, ...) THEN X ELSE Y END
WHERE  [field] = value

I used the ternary operator to choose between the two values to set and use the set function on the node object

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