【发布时间】:2011-05-30 06:19:26
【问题描述】:
我想将现有的 MySQL 表复制到一个重复的表中,但另外两个字段由从其他查询中检索到的数据填充。它适用于从未捕获线程的原始创建日期的论坛软件(它总是用最近的回复覆盖时间)。
所以我想取现有的表,'threads'
thread_id
thread_author
thread_subject
thread_last_reply_date
并创建一个新表“new_threads”,结构相同,但有两个额外字段:
thread_id
thread_author
thread_subject
thread_last_reply_date
thread_creation_date
thread_last_poster_id
thread_last_reply_date 和 thread_last_poster_id 都可以从相关查询中填充。例如,last_poster_id 的查询为:
SELECT post_author FROM posts WHERE thread_id = ? AND post_date = thread_last_reply_date
对于thread_creation_date:
SELECT MIN(post_date) FROM posts WHERE thread_id = ?
这基本上就是我使用 PHP 脚本执行的过程。一系列 SELECT,然后一个接一个地插入记录。任何关于如何在纯 SQL 中执行此类过程的建议或指导都会非常有帮助(如果可能的话)。
编辑:该技术的示例会有所帮助。我不需要上述的确切答案。我相信每个人都有更好的事情要做。
【问题讨论】: