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

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

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

      1. <tfoot id='hWaXS'></tfoot>

        如何从 mysql 表中选择最新的一组日期记录

        时间:2023-06-02
              <tbody id='96AQW'></tbody>
            <i id='96AQW'><tr id='96AQW'><dt id='96AQW'><q id='96AQW'><span id='96AQW'><b id='96AQW'><form id='96AQW'><ins id='96AQW'></ins><ul id='96AQW'></ul><sub id='96AQW'></sub></form><legend id='96AQW'></legend><bdo id='96AQW'><pre id='96AQW'><center id='96AQW'></center></pre></bdo></b><th id='96AQW'></th></span></q></dt></tr></i><div id='96AQW'><tfoot id='96AQW'></tfoot><dl id='96AQW'><fieldset id='96AQW'></fieldset></dl></div>
            <legend id='96AQW'><style id='96AQW'><dir id='96AQW'><q id='96AQW'></q></dir></style></legend>

            1. <tfoot id='96AQW'></tfoot>

                <bdo id='96AQW'></bdo><ul id='96AQW'></ul>

                  <small id='96AQW'></small><noframes id='96AQW'>

                • 本文介绍了如何从 mysql 表中选择最新的一组日期记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我将对各种 rpc 调用的响应存储在具有以下字段的 mysql 表中:

                  I am storing the response to various rpc calls in a mysql table with the following fields:

                  Table: rpc_responses
                  
                  timestamp   (date)
                  method      (varchar)
                  id          (varchar)
                  response    (mediumtext)
                  
                  PRIMARY KEY(timestamp,method,id)
                  

                  methodid 的所有现有组合选择最新响应的最佳方法是什么?

                  What is the best method of selecting the most recent responses for all existing combinations of method and id?

                  • 对于每个日期,给定的方法/ID 只能有一个响应.

                  • For each date there can only be one response for a given method/id.

                  对于给定日期,并非所有调用组合都必须存在.

                  Not all call combinations are necessarily present for a given date.

                  有数十种方法、数千个 ID 和至少 365 个不同的日期

                  There are dozens of methods, thousands of ids and at least 365 different dates

                  示例数据:

                  timestamp  method  id response
                  2009-01-10 getThud 16 "....."
                  2009-01-10 getFoo  12 "....."
                  2009-01-10 getBar  12 "....."
                  2009-01-11 getFoo  12 "....."
                  2009-01-11 getBar  16 "....."
                  

                  想要的结果:

                  2009-01-10 getThud 16 "....."
                  2009-01-10 getBar 12 "....."
                  2009-01-11 getFoo 12 "....."
                  2009-01-11 getBar 16 "....."
                  

                  (我不认为 this 是同一个问题- 它不会给我最新的 response)

                  (I don't think this is the same question - it won't give me the most recent response)

                  推荐答案

                  自我回答,但我不确定随着表格的增长,它是否会是一个足够有效的解决方案:

                  Self answered, but I'm not sure that it will be an efficient enough solution as the table grows:

                  SELECT timestamp,method,id,response FROM rpc_responses 
                  INNER JOIN
                  (SELECT max(timestamp),method,id FROM rpc_responses GROUP BY method,id) latest
                  USING (timestamp,method,id);
                  

                  这篇关于如何从 mysql 表中选择最新的一组日期记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 MySQL 中查找下一个可用的 id 下一篇:如何使用 LOAD DATA INFILE 将 CSV 文件中的选定列插入 MySQL 数据库

                  相关文章

                  1. <tfoot id='18M1q'></tfoot>

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

                        <bdo id='18M1q'></bdo><ul id='18M1q'></ul>