• <legend id='9q7d1'><style id='9q7d1'><dir id='9q7d1'><q id='9q7d1'></q></dir></style></legend>
    <tfoot id='9q7d1'></tfoot>

        <bdo id='9q7d1'></bdo><ul id='9q7d1'></ul>

        <small id='9q7d1'></small><noframes id='9q7d1'>

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

        当 Distinct 和 Group By 的表现不同时?

        When the performance of Distinct and Group By are different?(当 Distinct 和 Group By 的表现不同时?)
        • <small id='IyDgl'></small><noframes id='IyDgl'>

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

                • <legend id='IyDgl'><style id='IyDgl'><dir id='IyDgl'><q id='IyDgl'></q></dir></style></legend>
                • <tfoot id='IyDgl'></tfoot>
                • 本文介绍了当 Distinct 和 Group By 的表现不同时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我知道在简单查询中,Distinct 和 Group By 的性能和执行计划几乎相同.

                  I know in simple queries the performance and execution plans of the Distinct and Group By are almost the same.

                  例如

                  SELECT Name FROM NamesTable GROUP BY Name
                  SELECT DISTINCT Name FROM NamesTable
                  

                  但我在某些情况下读过他们的表现会有所不同,例如在子查询等中?

                  But I've read in some scenarios their performance would be different e.g. in subqueries, etc?

                  那么,您能否举一些例子或解释一些性能不同的场景?

                  So, could you make some examples or explain some scenarios where their performance are different?

                  非常感谢

                  推荐答案

                  如果在字段列表中包含计算值,您将看到执行计划中的差异.

                  If you include a calculated value in the field list you will see a difference in the execution plan.

                  select Value,
                         getdate()
                  from YourTable
                  group by UnitID
                  
                  select distinct
                         Value,
                         getdate()
                  from YourTable
                  

                  group by 查询在计算标量值之前进行聚合.distinct 查询在聚合之前计算标量值.

                  The group by query aggregates before it computes the scalar value. The distinct query computes the scalar value before the aggregate.

                  这篇关于当 Distinct 和 Group By 的表现不同时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                  Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)

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

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

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