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

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

      没有聚合函数的 GROUP BY

      时间:2023-09-19

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

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

              <tbody id='hrXQO'></tbody>

            1. <small id='hrXQO'></small><noframes id='hrXQO'>

              • <tfoot id='hrXQO'></tfoot>
                本文介绍了没有聚合函数的 GROUP BY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我试图在没有聚合函数的情况下理解 GROUP BY (oracle dbms 的新手).
                它是如何运作的?
                这是我尝试过的.

                我将在其上运行 SQL 的 EMP 表.

                SELECT ename , sal发件人按名称分组

                SELECT ename , sal发件人按名称分组;

                <块引用>

                结果

                ORA-00979:不是 GROUP BY 表达式
                00979. 00000 - 不是 GROUP BY 表达式"
                *原因:
                *动作:
                行错误:397 列:16

                SELECT ename , sal发件人按萨尔分组;

                <块引用>

                结果

                ORA-00979:不是 GROUP BY 表达式
                00979. 00000 - 不是 GROUP BY 表达式"
                *原因:
                *操作:错误行:411 列:8

                SELECT empno , ename , sal发件人GROUP BY 萨尔 , 名字;

                <块引用>

                结果

                ORA-00979:不是 GROUP BY 表达式
                00979. 00000 - 不是 GROUP BY 表达式"
                *原因:
                *操作:错误行:425 列:8

                SELECT empno , ename , sal发件人GROUP BY empno , ename , sal;

                所以,基本上列数必须等于 GROUP BY 子句中的列数,但我仍然不明白为什么或发生了什么.

                解决方案

                这就是 GROUP BY 的工作原理.它需要几行并将它们变成一行.因此,它必须知道如何处理某些列(字段)具有不同值的所有组合行.这就是为什么您对要 SELECT 的每个字段都有两个选项:要么将其包含在 GROUP BY 子句中,要么在聚合函数中使用它,以便系统知道您希望如何组合该字段.

                例如,假设您有这张表:

                名称 |订单号------------------约翰 |1约翰 |2

                如果你说 GROUP BY Name,它怎么知道在结果中显示哪个 OrderNumber?所以你要么在 group by 中包含 OrderNumber,这将导致这两行.或者,您使用聚合函数来展示如何处理 OrderNumber.例如MAX(OrderNumber),表示结果为John |2SUM(OrderNumber) 表示结果是 John |3.

                I am trying to understand GROUP BY (new to oracle dbms) without aggregate function.
                How does it operate?
                Here is what i have tried.

                EMP table on which i will run my SQL.

                SELECT ename , sal
                FROM emp
                GROUP BY ename , sal
                

                SELECT ename , sal  
                FROM emp  
                GROUP BY ename;  
                

                Result

                ORA-00979: not a GROUP BY expression
                00979. 00000 - "not a GROUP BY expression"
                *Cause:
                *Action:
                Error at Line: 397 Column: 16

                SELECT ename , sal  
                FROM emp  
                GROUP BY sal;  
                

                Result

                ORA-00979: not a GROUP BY expression
                00979. 00000 - "not a GROUP BY expression"
                *Cause:
                *Action: Error at Line: 411 Column: 8

                SELECT empno , ename , sal  
                FROM emp  
                GROUP BY sal , ename;  
                

                Result

                ORA-00979: not a GROUP BY expression
                00979. 00000 - "not a GROUP BY expression"
                *Cause:
                *Action: Error at Line: 425 Column: 8

                SELECT empno , ename , sal  
                FROM emp  
                GROUP BY empno , ename , sal;  
                

                So, basically the number of columns have to be equal to the number of columns in the GROUP BY clause, but i still do not understand why or what is going on.

                解决方案

                That's how GROUP BY works. It takes several rows and turns them into one row. Because of this, it has to know what to do with all the combined rows where there have different values for some columns (fields). This is why you have two options for every field you want to SELECT : Either include it in the GROUP BY clause, or use it in an aggregate function so the system knows how you want to combine the field.

                For example, let's say you have this table:

                Name | OrderNumber
                ------------------
                John | 1
                John | 2
                

                If you say GROUP BY Name, how will it know which OrderNumber to show in the result? So you either include OrderNumber in group by, which will result in these two rows. Or, you use an aggregate function to show how to handle the OrderNumbers. For example, MAX(OrderNumber), which means the result is John | 2 or SUM(OrderNumber) which means the result is John | 3.

                这篇关于没有聚合函数的 GROUP BY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Oracle 中的布尔字段 下一篇:如何从存储过程返回多行?(Oracle PL/SQL)

                相关文章

                • <bdo id='t7F35'></bdo><ul id='t7F35'></ul>
                <legend id='t7F35'><style id='t7F35'><dir id='t7F35'><q id='t7F35'></q></dir></style></legend>

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

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