【问题标题】:Insert into db2Table from an other table and own values从另一个表插入到 db2Table 并拥有自己的值
【发布时间】:2016-09-22 17:43:22
【问题描述】:

我有 table1 和 table2。我想将 table1 中的 a 列和 b 列插入 table2 和我自己的值(value1 和 value2)。 a 和 b 列非常大,这就是为什么我不想将它们导入到我的 java 应用程序中。此外,我需要 a 和 b 选择的 where 条件。我的preparedStatement 应该是什么样子?我的想法如下:

insert into table2 (columnvalue1, columnvalue2, a, b) as
    (select a, b from table1 where value3 = ? and value4 = ?)

【问题讨论】:

  • 不要调用列 value3 和 value4 等,这太混乱了。

标签: java sql db2


【解决方案1】:

类似:

insert into table2 (columnforvalue1, columnforvalue2, a, b)
    select value1, value2, a, b from table1 where value3 = ? and value4 = ?

或者

insert into table2 (columnforvalue1, columnforvalue2, a, b)
    select ?, ?, a, b from table1 where value3 = ? and value4 = ?

【讨论】:

  • 嘿,谢谢! db2怎么知道table1只有a和b,而我设置的其他已经是我要插入table2的局部变量了?
猜你喜欢
  • 2018-11-25
  • 1970-01-01
  • 2014-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多