1

我正在尝试将帖子的状态从“继承”更改为“已发布”,但仅限于日期在 08/01/2012 和 10/08/2012 之间的帖子。这是否是为实现此目的而运行的正确查询?

UPDATE wp_posts set post_status = replace(post_content, 'inherit', 'published') WHERE post_date BETWEEN '2012/08/01 00:00:00.000' AND '2012/10/08 23:59:00.000'
4

1 回答 1

1

如果post_status是单个值,则无需对其执行 a REPLACE()。只需将其设置为新值。MySQL 日期的格式应YYYY-MM-DD HH:ii:ss如下所示2012-08-01 00:00:00

UPDATE
  wp_posts
/* Set to the new status */
SET post_status = 'published'
WHERE
  /* Include the old status in the WHERE clause */
  post_status = 'inherit'
  AND post_date BETWEEN '2012-08-01 00:00:00' AND '2012-10-08 23:59:00'

REPLACE()方法虽然可行,但可能会导致查询速度慢得多,因为替换操作会在每一行中进行,但实际上只会对包含 string 的行产生影响inherit

于 2012-10-09T02:35:30.473 回答