MySQL将记录从多个表插入到新表 [英] MySQL Insert Records from Multiple Tables to New Table

查看:99
本文介绍了MySQL将记录从多个表插入到新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试用其他2个表中的记录填充新表.

I'm trying to populate a new table with records from 2 other tables.

period_states是新的/空的

period_states is new/empty

 period_states
   id
   period_id
   sla_id

期间-包含15条记录

periods
  id

slas-包含84条记录

slas - contains 84 records

slas
  id

我需要使用每个现有的sla_id和每个退出的period_id填充period_state.因此,最终在period_states中应该有1260条记录.

I need to populate period_states with each existing sla_id having each exiting period_id. So, ultimately there should be 1260 records in period_states.

有什么想法可以自动化吗?手动填充将是一场噩梦...

Any idea how to automate this? It would be a nightmare to populate manually...

先谢谢您!

推荐答案

INSERT INTO period_states
(period_id, sla_id)
SELECT periods.id, slas.id
FROM periods
CROSS JOIN slas

这篇关于MySQL将记录从多个表插入到新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆