<small id='4151J'></small><noframes id='4151J'>

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

    1. <tfoot id='4151J'></tfoot>

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

      1. 我可以将非聚合列与 group by 一起使用吗?

        Can I use non-aggregate columns with group by?(我可以将非聚合列与 group by 一起使用吗?)

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

                  <tbody id='AnaDF'></tbody>
                <legend id='AnaDF'><style id='AnaDF'><dir id='AnaDF'><q id='AnaDF'></q></dir></style></legend>
              1. <tfoot id='AnaDF'></tfoot>
                  <bdo id='AnaDF'></bdo><ul id='AnaDF'></ul>

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

                  本文介绍了我可以将非聚合列与 group by 一起使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  您不能(不应该)在 GROUP BY 查询的 SELECT 行中放置非聚合.

                  You cannot (should not) put non-aggregates in the SELECT line of a GROUP BY query.

                  然而,我想访问与最大值关联的非聚合之一.用简单的英语,我想要一个表,其中包含各种最旧的 ID.

                  I would however like access the one of the non-aggregates associated with the max. In plain english, I want a table with the oldest id of each kind.

                  CREATE TABLE stuff (
                     id int,
                     kind int,
                     age int
                  );
                  

                  这个查询给了我我想要的信息:

                  This query gives me the information I'm after:

                  SELECT kind, MAX(age)
                  FROM stuff
                  GROUP BY kind;
                  

                  但这并不是最有用的形式.我真的想要与每一行相关联的 id 以便我可以在以后的查询中使用它.

                  But it's not in the most useful form. I really want the id associated with each row so I can use it in later queries.

                  我正在寻找这样的东西:

                  I'm looking for something like this:

                  SELECT id, kind, MAX(age)
                  FROM stuff
                  GROUP BY kind;
                  

                  输出这个:

                  SELECT stuff.*
                  FROM
                     stuff,
                     ( SELECT kind, MAX(age)
                       FROM stuff
                       GROUP BY kind) maxes
                  WHERE
                     stuff.kind = maxes.kind AND
                     stuff.age = maxes.age
                  

                  似乎真的应该有一种无需加入即可获取此信息的方法.我只需要 SQL 引擎在计算最大值时记住其他列.

                  It really seems like there should be a way to get this information without needing to join. I just need the SQL engine to remember the other columns when it's calculating the max.

                  推荐答案

                  无法获取 MAX 找到的行的 id,因为最长年龄的 id 可能不止一个.

                  You can't get the Id of the row that MAX found, because there might not be only one id with the maximum age.

                  这篇关于我可以将非聚合列与 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 行为不同)
                  <legend id='gakch'><style id='gakch'><dir id='gakch'><q id='gakch'></q></dir></style></legend>
                  • <i id='gakch'><tr id='gakch'><dt id='gakch'><q id='gakch'><span id='gakch'><b id='gakch'><form id='gakch'><ins id='gakch'></ins><ul id='gakch'></ul><sub id='gakch'></sub></form><legend id='gakch'></legend><bdo id='gakch'><pre id='gakch'><center id='gakch'></center></pre></bdo></b><th id='gakch'></th></span></q></dt></tr></i><div id='gakch'><tfoot id='gakch'></tfoot><dl id='gakch'><fieldset id='gakch'></fieldset></dl></div>

                          <bdo id='gakch'></bdo><ul id='gakch'></ul>
                            <tbody id='gakch'></tbody>
                          <tfoot id='gakch'></tfoot>

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