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

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

          <bdo id='hPqmv'></bdo><ul id='hPqmv'></ul>
      1. 如何通过 MYSQL 中的另一列选择具有 MAX(列值)、

        时间:2023-08-19
        <tfoot id='ksoYs'></tfoot>
        • <small id='ksoYs'></small><noframes id='ksoYs'>

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

                    <tbody id='ksoYs'></tbody>
                  <i id='ksoYs'><tr id='ksoYs'><dt id='ksoYs'><q id='ksoYs'><span id='ksoYs'><b id='ksoYs'><form id='ksoYs'><ins id='ksoYs'></ins><ul id='ksoYs'></ul><sub id='ksoYs'></sub></form><legend id='ksoYs'></legend><bdo id='ksoYs'><pre id='ksoYs'><center id='ksoYs'></center></pre></bdo></b><th id='ksoYs'></th></span></q></dt></tr></i><div id='ksoYs'><tfoot id='ksoYs'></tfoot><dl id='ksoYs'><fieldset id='ksoYs'></fieldset></dl></div>
                  本文介绍了如何通过 MYSQL 中的另一列选择具有 MAX(列值)、PARTITION 的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我的桌子是:

                  <头>
                  id日期时间玩家资源
                  11004/03/2009约翰399
                  21104/03/2009朱丽叶244
                  51204/03/2009硼酸555
                  31003/03/2009约翰300
                  41103/03/2009朱丽叶200
                  61203/03/2009硼酸500
                  71324/12/2008硼酸600
                  81301/01/2009硼酸700

                  我需要选择每个不同的 home 保存 datetime 的最大值.

                  I need to select each distinct home holding the maximum value of datetime.

                  结果是:

                  <头>
                  id日期时间玩家资源
                  11004/03/2009约翰399
                  21104/03/2009朱丽叶244
                  51204/03/2009硼酸555
                  81301/01/2009硼酸700

                  我试过了:

                  -- 1 ..by the MySQL manual: 
                  
                  SELECT DISTINCT
                    home,
                    id,
                    datetime AS dt,
                    player,
                    resource
                  FROM topten t1
                  WHERE datetime = (SELECT
                    MAX(t2.datetime)
                  FROM topten t2
                  GROUP BY home)
                  GROUP BY datetime
                  ORDER BY datetime DESC
                  

                  不起作用.结果集有 130 行,尽管数据库有 187 行.结果包括 home 的一些重复项.

                  Doesn't work. Result-set has 130 rows although database holds 187. Result includes some duplicates of home.

                  -- 2 ..join
                  
                  SELECT
                    s1.id,
                    s1.home,
                    s1.datetime,
                    s1.player,
                    s1.resource
                  FROM topten s1
                  JOIN (SELECT
                    id,
                    MAX(datetime) AS dt
                  FROM topten
                  GROUP BY id) AS s2
                    ON s1.id = s2.id
                  ORDER BY datetime 
                  

                  没有.提供所有记录.

                  -- 3 ..something exotic: 
                  

                  各种结果.

                  推荐答案

                  你们离得这么近!您需要做的就是选择家庭及其最大日期时间,然后在两个字段中加入 topten 表:

                  You are so close! All you need to do is select BOTH the home and its max date time, then join back to the topten table on BOTH fields:

                  SELECT tt.*
                  FROM topten tt
                  INNER JOIN
                      (SELECT home, MAX(datetime) AS MaxDateTime
                      FROM topten
                      GROUP BY home) groupedtt 
                  ON tt.home = groupedtt.home 
                  AND tt.datetime = groupedtt.MaxDateTime
                  

                  这篇关于如何通过 MYSQL 中的另一列选择具有 MAX(列值)、PARTITION 的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:MySQL 中的 ROW_NUMBER() 下一篇:获取每组分组结果的前 n 条记录

                  相关文章

                  最新文章

                    <tfoot id='drTr9'></tfoot>

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

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