<bdo id='s8nYD'></bdo><ul id='s8nYD'></ul>
<i id='s8nYD'><tr id='s8nYD'><dt id='s8nYD'><q id='s8nYD'><span id='s8nYD'><b id='s8nYD'><form id='s8nYD'><ins id='s8nYD'></ins><ul id='s8nYD'></ul><sub id='s8nYD'></sub></form><legend id='s8nYD'></legend><bdo id='s8nYD'><pre id='s8nYD'><center id='s8nYD'></center></pre></bdo></b><th id='s8nYD'></th></span></q></dt></tr></i><div id='s8nYD'><tfoot id='s8nYD'></tfoot><dl id='s8nYD'><fieldset id='s8nYD'></fieldset></dl></div>
  • <small id='s8nYD'></small><noframes id='s8nYD'>

  • <tfoot id='s8nYD'></tfoot>

      1. <legend id='s8nYD'><style id='s8nYD'><dir id='s8nYD'><q id='s8nYD'></q></dir></style></legend>
      2. 使用另一个选择查询的结果将数据插入表中

        Insert data into table with result from another select query(使用另一个选择查询的结果将数据插入表中)
          • <bdo id='vbzCl'></bdo><ul id='vbzCl'></ul>

              <tbody id='vbzCl'></tbody>
              <tfoot id='vbzCl'></tfoot>

              <small id='vbzCl'></small><noframes id='vbzCl'>

              <i id='vbzCl'><tr id='vbzCl'><dt id='vbzCl'><q id='vbzCl'><span id='vbzCl'><b id='vbzCl'><form id='vbzCl'><ins id='vbzCl'></ins><ul id='vbzCl'></ul><sub id='vbzCl'></sub></form><legend id='vbzCl'></legend><bdo id='vbzCl'><pre id='vbzCl'><center id='vbzCl'></center></pre></bdo></b><th id='vbzCl'></th></span></q></dt></tr></i><div id='vbzCl'><tfoot id='vbzCl'></tfoot><dl id='vbzCl'><fieldset id='vbzCl'></fieldset></dl></div>

                <legend id='vbzCl'><style id='vbzCl'><dir id='vbzCl'><q id='vbzCl'></q></dir></style></legend>

                  本文介绍了使用另一个选择查询的结果将数据插入表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在就以下问题寻求帮助:我有两张桌子Table_1 列分别是itemidlocationidquantity

                  Table_2 列分别是 itemidlocation1location2location3

                  我想将数据从Table_1(只有quantity 列)复制到Table_2(到location1 列).itemid 在两个表中是相同的(Table_1 有重复的项目 ID)所以这就是我想复制到一个新表并将所有数量保留在一行中的原因每个位置作为一列.我正在使用以下查询,但它不起作用

                  插入表_2(位置1)(选择数量从表_1WHERE locationid = 1 AND Table_1.locationid = Table_2.locationid)

                  解决方案

                  如果 table_2 为空,则尝试以下插入语句:

                  insert into table_2 (itemid,location1)select itemid,quantity from table_1 where locationid=1

                  如果 table_2 已经包含 itemid 值,那么试试这个更新语句:

                  update table_2 set location1=(从 table_1 中选择数量,其中 locationid=1 和 table_1.itemid = table_2.itemid)

                  I am seeking help on the following issue: I have two tables Table_1 columns are itemid, locationid, quantity

                  Table_2 columns are itemid, location1, location2, location3

                  I want to copy data from Table_1 (only quantity column) into Table_2 (into location1 column). The itemid are same in both the tables(Table_1 has duplicate item id's) so that's the reason I want to copy to a new table and keep all quantity in one single row with each location as a column. I am using the below query but it doesn't work

                  INSERT INTO 
                  Table_2(location1) 
                  (
                   SELECT qty 
                   FROM Table_1 
                   WHERE locationid = 1 AND Table_1.locationid = Table_2.locationid
                  )
                  

                  解决方案

                  If table_2 is empty, then try the following insert statement:

                  insert into table_2 (itemid,location1) 
                  select itemid,quantity from table_1 where locationid=1
                  

                  If table_2 already contains the itemid values, then try this update statement:

                  update table_2 set location1=
                  (select quantity from table_1 where locationid=1 and table_1.itemid = table_2.itemid)
                  

                  这篇关于使用另一个选择查询的结果将数据插入表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  SQL Server Bulk insert of CSV file with inconsistent quotes(SQL Server 批量插入带有不一致引号的 CSV 文件)
                  How to update a record using sequelize for node?(如何使用节点的 sequelize 更新记录?)
                  How to provide a mysql database connection in single file in nodejs(如何在 nodejs 中的单个文件中提供 mysql 数据库连接)
                  Looping Over Result Sets in MySQL(在 MySQL 中循环结果集)
                  SQL - Inserting a row and returning primary key(SQL - 插入一行并返回主键)
                  Python and SQLite: insert into table(Python 和 SQLite:插入表)

                  <legend id='4saCC'><style id='4saCC'><dir id='4saCC'><q id='4saCC'></q></dir></style></legend>
                          <tbody id='4saCC'></tbody>
                        <tfoot id='4saCC'></tfoot>

                        <small id='4saCC'></small><noframes id='4saCC'>

                      1. <i id='4saCC'><tr id='4saCC'><dt id='4saCC'><q id='4saCC'><span id='4saCC'><b id='4saCC'><form id='4saCC'><ins id='4saCC'></ins><ul id='4saCC'></ul><sub id='4saCC'></sub></form><legend id='4saCC'></legend><bdo id='4saCC'><pre id='4saCC'><center id='4saCC'></center></pre></bdo></b><th id='4saCC'></th></span></q></dt></tr></i><div id='4saCC'><tfoot id='4saCC'></tfoot><dl id='4saCC'><fieldset id='4saCC'></fieldset></dl></div>
                            <bdo id='4saCC'></bdo><ul id='4saCC'></ul>