0

我知道你可以这样做:

INSERT INTO AnotherTable (a, b, c, d)
SELECT a, b, c, d
FROM SomeTable
WHERE SomeColumn = 1

但是,如果SELECT a, b, c, d您需要将这些列更新为a, b, c, "string"

说白了,我想要一个声明:

INSERT INTO AnotherTable (a, b, c, d)
SELECT a, b
FROM SomeTable
WHERE SomeColumn = 1
// And put  "string" into d

更新

所以我运行了这个:

INSERT INTO AnotherTable (a, b, c, d)
SELECT a, b, c, 'string'
FROM SomeTable
WHERE SomeColumn = 1

它在“c”列中选择了 3 行具有不同条目的行,并通过插入完全相同的 3 行来更新“AnotherTable”。尽管它们应该是不同的值...

4

2 回答 2

1
INSERT INTO AnotherTable (a, b, c, d)
SELECT a, b,"SOME VALE","SOMEVALUE2"
FROM SomeTable
WHERE SomeColumn = 1
于 2013-04-25T08:50:41.173 回答
0
INSERT INTO AnotherTable (a, b, c, d)
SELECT a, b, $somevar, 'fixed string'
FROM SomeTable
WHERE SomeColumn = 1

但是,您应该非常小心地注入这样的 $somevar。真的你应该使用准备好的语句,所以它会......

INSERT INTO AnotherTable (a, b, c, d)
SELECT a, b, :CustomValue, 'fixed string'
FROM SomeTable
WHERE SomeColumn = 1

并且 CustomValue 是通过将值绑定到语句来设置的。这里有一些例子:http ://www.php.net/manual/en/pdostatement.bindvalue.php

于 2013-04-25T08:50:13.207 回答