我有以下表结构:
// Posts
+----+---------+-----------------+------------------+------------------------+------------------------+
| id | title | content_html | content_markdown | content_edit_html | content_edit_markdown |
+----+---------+-----------------+------------------+------------------------+------------------------+
| 1 | title1 | <b>content1</b> | **content1** | <b>content1_edited</b> | **content1_edited** |
| 2 | title2 | <i>content2</i> | *content2* | | |
+----+---------+-----------------+------------------+------------------------+------------------------+
正如您在上表中看到的那样,我只保留了最后一次编辑(content(html/markdown)
是最后一次修改前的内容,或者内容未经编辑,content_edit(html/markdown)
是最后一次修改,如果没有&#39则为空; t任何编辑)
现在请看看这两个例子:
示例一:我想编辑已编辑的第一篇 。这是新的价值:
**content1_new_value**
我还使用PHP库将其转换为html并将其转换为:
<b>content1_new_value</b>
我想用content_(html/markdown)
的当前内容填充(更新)content_edit_(html/markdown)
的内容,并使用新值填充(更新)此列content_edit_(html/markdown)
,如下所示:
+----+---------+------------------------+----------------------+----------------------------+------------------------+
| id | title | content_html | content_markdown | content_edit_html | content_edit_markdown |
+----+---------+------------------------+----------------------+----------------------------+------------------------+
| 1 | title1 | <b>content1_edited</b> | **content1_edited** | <b>content1_new_value</b> | **content1_new_value** |
+----+---------+------------------------+----------------------+----------------------------+------------------------+
示例二:我想编辑已编辑的第二篇 。这是新的价值:
*content2_new_value*
我还使用PHP库将其转换为html并将其转换为:
<i>content2_new_value</i>
在这种情况下,我希望保持content_(html/markdown)
完整(没有任何更改),只需使用新值更新content_edited_(html/markdown)
,如下所示:
+----+---------+-----------------+------------------+------------------------+--------------------------+
| id | title | content_html | content_markdown | content_edit_html | content_edit_markdown |
+----+---------+-----------------+------------------+------------------------+--------------------------+
| 2 | title2 | <i>content2</i> | *content2* | *content2_new_value* | <i>content2_new_value</i>|
+----+---------+-----------------+------------------+------------------------+--------------------------+
如你所见,我只保留最后两次编辑。我怎么能这样做?
答案 0 :(得分:2)
结束时检查案例
case
when content_edit_html is not null
update table set content_html = content_edit_html, content_markdown = content_edit_markdown,
content_edit_html = <b>content1_new_value</b>, content_edit_markdown = **content_new_value**
where id = 1
else
update table set content_edit_html = <b>content1_new_value</b>, content_edit_markdown = **content_new_value**
where id = 1
end