• <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 的表现不同时?

        时间:2024-04-16
        • <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 的表现不同时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 MySQL 中使用 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>
                      <bdo id='nnfcL'></bdo><ul id='nnfcL'></ul>
                  1. <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>