1. <legend id='3YyIA'><style id='3YyIA'><dir id='3YyIA'><q id='3YyIA'></q></dir></style></legend>

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

      <small id='3YyIA'></small><noframes id='3YyIA'>

        <bdo id='3YyIA'></bdo><ul id='3YyIA'></ul>
    1. oracle中select语句中的子查询是如何工作的

      How does Subquery in select statement work in oracle(oracle中select语句中的子查询是如何工作的)

      1. <legend id='2xLgH'><style id='2xLgH'><dir id='2xLgH'><q id='2xLgH'></q></dir></style></legend>

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

          <small id='2xLgH'></small><noframes id='2xLgH'>

              <bdo id='2xLgH'></bdo><ul id='2xLgH'></ul>
                <tbody id='2xLgH'></tbody>
                本文介绍了oracle中select语句中的子查询是如何工作的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我已经翻遍了关于select语句中的子查询如何工作的解释,但由于非常模糊的解释,我仍然无法理解这个概念.

                I have looked all over for an explanation, to how does the subquery in a select statement work and still I cannot grasp the concept because of very vague explanations.

                我想知道你如何在oracle的select语句中使用子查询以及它究竟输出什么.

                I would like to know how do you use a subquery in a select statement in oracle and what exactly does it output.

                例如,如果我有一个查询想要显示员工的姓名以及他们从这些表中管理的个人资料数量

                For example, if i had a query that wanted to display the names of employees and the number of profiles they manage from these tables

                员工(EmpName, EmpId)

                Employee(EmpName, EmpId)

                配置文件(ProfileId, ..., EmpId)

                Profile(ProfileId, ..., EmpId)

                如何使用子查询?

                我想在 select 语句中需要一个子查询来实现 group by 函数来计算每个员工管理的配置文件的数量,但我不太确定.

                I was thinking a subquery is needed in the select statement to implement the group by function to count the number of profiles being managed for each employee, but I am not too sure.

                推荐答案

                很简单-

                SELECT empname,
                       empid,
                       (SELECT COUNT (profileid)
                          FROM profile
                         WHERE profile.empid = employee.empid)
                           AS number_of_profiles
                  FROM employee;
                

                当你使用像这样的表连接时,它会更简单:

                It is even simpler when you use a table join like this:

                  SELECT e.empname, e.empid, COUNT (p.profileid) AS number_of_profiles
                    FROM employee e LEFT JOIN profile p ON e.empid = p.empid
                GROUP BY e.empname, e.empid;
                

                <小时>

                对子查询的解释:

                本质上,select 中的子查询获取标量值并将其传递给主查询.select 中的子查询不能传递多于一行和多于一列,这是一个限制.在这里,我们将一个 count 传递给主查询,正如我们所知,它始终只是一个数字——一个标量值.如果未找到值,子查询将 null 返回到主查询.此外,子查询可以访问主查询的 from 子句中的列,如我的查询所示,其中 employee.empid 从外部查询传递到内部查询.

                Essentially, a subquery in a select gets a scalar value and passes it to the main query. A subquery in select is not allowed to pass more than one row and more than one column, which is a restriction. Here, we are passing a count to the main query, which, as we know, would always be only a number- a scalar value. If a value is not found, the subquery returns null to the main query. Moreover, a subquery can access columns from the from clause of the main query, as shown in my query where employee.empid is passed from the outer query to the inner query.

                编辑:

                当您在 select 子句中使用子查询时,Oracle 本质上将其视为左连接(您可以在 为您的查询解释计划),对于左侧的每一行,行的基数只是右侧的一个.

                When you use a subquery in a select clause, Oracle essentially treats it as a left join (you can see this in the explain plan for your query), with the cardinality of the rows being just one on the right for every row in the left.

                左连接说明

                左连接非常方便,特别是当你想替换 select 子查询时,因为它的限制.此处对LEFT JOIN 关键字两侧的表的行数没有限制.

                A left join is very handy, especially when you want to replace the select subquery due to its restrictions. There are no restrictions here on the number of rows of the tables in either side of the LEFT JOIN keyword.

                有关详细信息,请阅读 关于子查询的 Oracle 文档 和 左连接或左外连接.

                For more information read Oracle Docs on subqueries and left join or left outer join.

                这篇关于oracle中select语句中的子查询是如何工作的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                Accessing another user#39;s table within an Oracle Stored Procedure(在 Oracle 存储过程中访问另一个用户的表)
                Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)(超出最大存储过程、函数、触发器或视图嵌套级别(限制 32))
                How to View Oracle Stored Procedure using SQLPlus?(如何使用 SQLPlus 查看 Oracle 存储过程?)
                How to debug stored procedure in VS 2015?(如何在 VS 2015 中调试存储过程?)
                How to Pass Java List of Objects to Oracle Stored Procedure Using MyBatis?(如何使用 MyBatis 将 Java 对象列表传递给 Oracle 存储过程?)
                Set the variable result, from query(设置变量结果,来自查询)
                1. <i id='l3OjB'><tr id='l3OjB'><dt id='l3OjB'><q id='l3OjB'><span id='l3OjB'><b id='l3OjB'><form id='l3OjB'><ins id='l3OjB'></ins><ul id='l3OjB'></ul><sub id='l3OjB'></sub></form><legend id='l3OjB'></legend><bdo id='l3OjB'><pre id='l3OjB'><center id='l3OjB'></center></pre></bdo></b><th id='l3OjB'></th></span></q></dt></tr></i><div id='l3OjB'><tfoot id='l3OjB'></tfoot><dl id='l3OjB'><fieldset id='l3OjB'></fieldset></dl></div>

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

                    <tfoot id='l3OjB'></tfoot>

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

                      <tbody id='l3OjB'></tbody>
                    • <bdo id='l3OjB'></bdo><ul id='l3OjB'></ul>