Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将insert调整为SQL_Sql_Insert Into - Fatal编程技术网

将insert调整为SQL

将insert调整为SQL,sql,insert-into,Sql,Insert Into,我已经开始工作了 INSERT INTO TermsFinal (old_classification, count, new_classification, old_term,new_term) SELECT old_classification , Count(seed) AS count , new_classification, old_term, new_term FROM TermsTemp GRO

我已经开始工作了

    INSERT INTO TermsFinal 
            (old_classification, count, new_classification, old_term,new_term) 
        SELECT  old_classification   , Count(seed) AS count , new_classification, old_term, new_term FROM   TermsTemp
            GROUP  BY old_classification
            ORDER  BY count DESC    
TermsFinal中还有一个名为SOURCE_表的字段,TermsTemp没有该字段。 我也想填充该字段。我已经得到$source\u表的值。我试过了,但没用

    INSERT INTO TermsFinal 
            (SOURCE_TABLE,old_classification, count, new_classification, old_term,new_term) 
    '{$SOURCE_TABLE}',  SELECT  old_classification   , Count(seed) AS count , new_classification, old_term, new_term FROM   TermsTemp_TEMP
            GROUP  BY old_classification
            ORDER  BY count DESC
在一次性执行insert into语句时,如何将该值添加到TermsFinal的SOURCE_TABLE字段中

另一件让我感到困惑的事情是,为什么我的第一个SQL插件在没有SQL关键字值的情况下工作。本页说明需要零件

例如,您可以将字符串(或任何其他类型)常量放入select
选择“string”作为const_str,表1中的field1将返回两列,第一列将为所有行提供“string”文本。在你的情况下,你可以这样做

 INSERT INTO TermsFinal 
        (SOURCE_TABLE,old_classification, count, new_classification, old_term,new_term) 
  SELECT  '{$SOURCE_TABLE}', old_classification   , Count(seed) AS count , new_classification, old_term, new_term FROM   TermsTemp_TEMP
        GROUP  BY old_classification
        ORDER  BY count DESC
例如,您可以将字符串(或任何其他类型)常量放入select
选择“string”作为const_str,表1中的field1将返回两列,第一列将为所有行提供“string”文本。在你的情况下,你可以这样做

 INSERT INTO TermsFinal 
        (SOURCE_TABLE,old_classification, count, new_classification, old_term,new_term) 
  SELECT  '{$SOURCE_TABLE}', old_classification   , Count(seed) AS count , new_classification, old_term, new_term FROM   TermsTemp_TEMP
        GROUP  BY old_classification
        ORDER  BY count DESC

有几种方法可以将数据插入表中

一次一行。这是需要values关键字的地方

Insert into TableA (Col1, Col2,...) values (@Val1, @Val2,...)
如果您具有自动标识,则可以使用“选择@@identity”(至少在ms sql中)获取id 在…上当您需要下一次插入的ID时,这非常有用

从选择(您正在做的事情)

或插入硬编码值和两个单独表中的值

Insert into tableA (Col1, Col2, Col3, Col4)
Select 'hard coded value', b.Val1, b.Val2, c.Val1 
from TableB b join Table c on b.TableCID=c.ID
现在可以一次插入多行

选择进入

此方法最终从查询创建一个新表,非常适合于表或表的一部分的快速备份

select * into TermsFinal_backup from TermsFinal where ...

有几种方法可以将数据插入表中

一次一行。这是需要values关键字的地方

Insert into TableA (Col1, Col2,...) values (@Val1, @Val2,...)
如果您具有自动标识,则可以使用“选择@@identity”(至少在ms sql中)获取id 在…上当您需要下一次插入的ID时,这非常有用

从选择(您正在做的事情)

或插入硬编码值和两个单独表中的值

Insert into tableA (Col1, Col2, Col3, Col4)
Select 'hard coded value', b.Val1, b.Val2, c.Val1 
from TableB b join Table c on b.TableCID=c.ID
现在可以一次插入多行

选择进入

此方法最终从查询创建一个新表,非常适合于表或表的一部分的快速备份

select * into TermsFinal_backup from TermsFinal where ...