我想在新数据库中插入最近的三行?
+------------+----------+---------+--------------+--------------+-----------+--------------+--------+------+--------------+
| time | userid | groupid | jobs_running | jobs_pending | job_limit |
+------------+----------+---------+--------------+--------------+-----------+--------------+--------+------+--------------+
| 1476274005 | achandra | | 4 | 0 | 0 |
| 1476274005 | akawle | | 52 | 48 | 0 |
| 1476274005 | apatil2 | | 20 | 6 | 0 |
| 1476274793 | snagnoor | | 17 | 67 | 0 |
| 1476274793 | snatara2 | | 0 | 54 | 0 |
| 1476274793 | sthykkoo | | 9 | 476 | 0 |
预期产出:
| 1476274793 | snagnoor | | 17 | 67 | 0 |
| 1476274793 | snatara2 | | 0 | 54 | 0 |
| 1476274793 | sthykkoo | | 9 | 476 | 0 |
答案 0 :(得分:1)
我认为这个查询会有效。
db2
是新数据库,db1
是旧的,您必须复制表格
insert into db2.`new_table_name` select * from db1.old_table order by `time` desc limit 3
PS。此代码未经测试。