<bdo id='BojKC'></bdo><ul id='BojKC'></ul>
    <tfoot id='BojKC'></tfoot>
    <legend id='BojKC'><style id='BojKC'><dir id='BojKC'><q id='BojKC'></q></dir></style></legend>
  1. <small id='BojKC'></small><noframes id='BojKC'>

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

    1. 如何在 MySQL 的“插入"语句中使用“选择"

      How to use #39;select #39; in MySQL #39;insert#39; statement(如何在 MySQL 的“插入语句中使用“选择)

          • <bdo id='RTfyv'></bdo><ul id='RTfyv'></ul>
          • <small id='RTfyv'></small><noframes id='RTfyv'>

          • <i id='RTfyv'><tr id='RTfyv'><dt id='RTfyv'><q id='RTfyv'><span id='RTfyv'><b id='RTfyv'><form id='RTfyv'><ins id='RTfyv'></ins><ul id='RTfyv'></ul><sub id='RTfyv'></sub></form><legend id='RTfyv'></legend><bdo id='RTfyv'><pre id='RTfyv'><center id='RTfyv'></center></pre></bdo></b><th id='RTfyv'></th></span></q></dt></tr></i><div id='RTfyv'><tfoot id='RTfyv'></tfoot><dl id='RTfyv'><fieldset id='RTfyv'></fieldset></dl></div>
              <tfoot id='RTfyv'></tfoot>
                <tbody id='RTfyv'></tbody>
            1. <legend id='RTfyv'><style id='RTfyv'><dir id='RTfyv'><q id='RTfyv'></q></dir></style></legend>

                本文介绍了如何在 MySQL 的“插入"语句中使用“选择"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试向需要从另一个表中检索值的表中插入额外的行.下面是一个示例查询:

                I'm trying to insert additional rows into a table which requires a value to be retrieved from another table. Below is an example query:

                insert into a.grades (rollno, grade)
                values(select rollno from b.students where ssn=12345, 'A');
                

                b.students 表的结构是rollno, ssn, name.

                我知道上面的查询是错误的.有没有办法在插入行时从其他表中检索 1 个值?

                I knew the above query is wrong. Is there a way to retrieve 1 value from other table while inserting a row?

                推荐答案

                INSERT INTO a.grades (rollno, grade)
                    SELECT rollno, 'A' FROM b.students WHERE ssn = 12345;
                

                某些 DBMS 会接受以下内容,并在 SELECT 语句周围加上一组额外的括号:

                Some DBMS would accept the following, with an extra set of parenthesis around the SELECT statement:

                INSERT INTO a.grades (rollno, grade)
                   VALUES((SELECT rollno FROM b.students WHERE ssn = 12345), 'A');
                

                这篇关于如何在 MySQL 的“插入"语句中使用“选择"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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:插入表)
                    <tbody id='qW6tS'></tbody>
                  <legend id='qW6tS'><style id='qW6tS'><dir id='qW6tS'><q id='qW6tS'></q></dir></style></legend>

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

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