根据查询插入insert into select from
最后更新:2024-09-01 05:30:17
|
状态:未完成
数量比较大时,可以直接根据SELECT插入,跳过网络IO会快许多 //INSERT INTO A SELECT * FROM B //与查询方法参数一致,在查询方法基础上 加一个插入目标表 ServiceProxy.insert("crm_user(ID,CODE)", "sso_user(ID,CODE)", "id > 0"); //INSERT INTO CRM_USER(ID, CODE) SELECT ID, CODE FROM SSO_USER WHERE ID > 0 ConfigStore configs = new DefaultConfigStore(); configs.and("ID", 1); Table tab = new Table<>("crm_user"); tab.addColumn(new Column("ID")); tab.addColumn(new Column("CODE")); ServiceProxy.insert(tab, new Table("crm_user"), configs.columns("BID","BCODE")); //INSERT INTO CRM_USER(ID, CODE) SELECT BID, BCODE FROM SSO_USER WHERE ID = 1 //复杂的查询可以先构造RunPrepare RunPrepare prepare = TableBuilder.init("crm_user(a.id, b.code) as a").left("hr_user as b","a.id = b.id").build(); ServiceProxy.insert("crm_user(id,code)", prepare,0,9, "a.id>1"); /*INSERT INTO crm_user(id, code) SELECT a.id,b.code FROM crm_user a LEFT JOIN hr_user b ON a.id = b.id WHERE a.id>1 LIMIT 10 OFFSET 0 */