如何用java将数据库的多表整合到一个表
问题描述:
答
你想整合到一个表里面肯定是要新建表的,现有的表结构不支持存储所有表的数据。
新表的表结构就是id callid called count t_count m_count ut_count um_count
insert into newtable (select a.id,a.callid,a.called,a.count,b.t_count,c.m_count from table1 a left join table2 b on a.id=b.id left join table3 c on a.id=c.id )
我是按照id单字段链接的,也可以用id callid called三字段链接
省略了两张表,链接方法是一样的。
答
新建一张表,写sql 插入就行了啊
答
你这个不同的表 主键Id是一样的 所以你在整合到一张表的时候 注意设置新的主键
不能拿之前的id作为主键 不然主键冲突
答
你可以使用 select into 语句 或者使用 insert into select 语句