我正在尝试编写一个mysql查询来将数据从现有表传输到新表和 我不知道该怎么做。
这是目标表,保留已访问主题的记录,以将其标记为已读/未读:
mysql> describe topic_tracking;
+------------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------------+------+-----+---------+-------+
| user_id | int(10) unsigned | NO | PRI | NULL | |
| topic_id | int(10) unsigned | NO | PRI | NULL | |
| mark_time | datetime | NO | | NULL | |
+------------+------------------+------+-----+---------+-------+
和包含数据的旧的(将被新的替换)
mysql> describe topic_seen;
+----------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| user_id | int(10) unsigned | NO | MUL | NULL | |
| topic_id | int(10) unsigned | NO | MUL | NULL | |
| count | int(10) unsigned | NO | | 0 | |
+----------+------------------+------+-----+---------+----------------+
topic_seen.count - 主题话题中读取的用户消息数
mysql> describe topic_posts;
+-----------+------------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+------------------+------+-----+---------------------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| topic_id | int(10) unsigned | NO | MUL | NULL | |
| post_time | datetime | NO | | 0000-00-00 00:00:00 | |
| user_id | int(10) unsigned | NO | MUL | NULL | |
| txt | text | YES | | NULL | |
+-----------+------------------+------+-----+---------------------+----------------+
我需要获取线程中最后一条读取消息的topic_posts.post_time
,并使用topic_tracking.mark_time
topic_seen.count