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

      1. <small id='74T2f'></small><noframes id='74T2f'>

        如何从我的 mysql 中选择最新的 5 行

        how to select the 5 latest row from my mysql(如何从我的 mysql 中选择最新的 5 行)
          <tbody id='l6oZD'></tbody>

      2. <tfoot id='l6oZD'></tfoot>

            • <small id='l6oZD'></small><noframes id='l6oZD'>

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

                <bdo id='l6oZD'></bdo><ul id='l6oZD'></ul>
                  本文介绍了如何从我的 mysql 中选择最新的 5 行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想知道从我的表中检索 5 个最新行的 sql 命令?下面是我的 sql 查询.我该怎么办,以便它可以选择基于第 5 行 的最新行进行处理?

                  I wanted to know the sql command to retrieve 5 latest row from my table? Below is my sql query. How am I going to do, in order it can select the 5 latest row base on row no to be process?

                  $query = 
                  "SELECT lat, lng, DATE_FORMAT(datetime,'%W %M %D, %Y %T') AS 
                    datetime FROM markers1 WHERE 1";
                  

                  推荐答案

                  需要对结果进行排序,并设置一个限制.

                  You need to order the results, and set a limit.

                  假设日期时间是您要订购的时间:

                  Assuming datetime is what you wanted to order on:

                  $query = "
                      SELECT 
                          lat, 
                          lng, 
                          DATE_FORMAT(datetime,'%W %M %D, %Y %T') AS datetime 
                      FROM markers1 WHERE 1
                      ORDER BY datetime DESC
                      LIMIT 5
                  ";
                  

                  <小时>

                  回答 OP 的评论:我得到的结果是第 50 行的第一个查询开始,然后是 49,48,47,46 是否有可能我可以从第 46,47,48,49,50 行开始?"


                  To answer OP's comment: "result that i get is start for Row 50 for first query and it follow by 49,48,47,46 Is that possible i can get this start frm row 46,47,48,49,50 ?"

                  您可以在 PHP 中使用结果执行此操作,方法是获取行并将它们存储在数组中并反转数组.我不相信您可以有效地反向循环遍历 mysql 结果资源.

                  You could either do this with the result in PHP, by fetching the rows and storing them in an array and reversing the array. I don't believe you can efficiently loop through a mysql result resource in reverse.

                  要在 SQL 查询中执行此操作,您需要使用原始查询创建一个临时表:

                  To do this in the SQL query, you need to create a temporary table with the original query:

                  $query = "
                      SELECT 
                          lat,
                          lng,
                          DATE_FORMAT(datetime,'%W %M %D, %Y %T') AS datetime 
                      FROM (
                          SELECT 
                              lat, 
                              lng, 
                              datetime
                          FROM markers1 WHERE 1
                          ORDER BY datetime DESC
                          LIMIT 5
                      ) AS tmp_markers
                      ORDER BY datetime ASC
                  ";
                  

                  初始查询的结果用作在新查询中搜索的表,该查询按日期时间升序排列.我不得不在外部查询上应用 DATE_FORMAT,因为我们需要再次订购日期时间字段.

                  The result of the initial query is used as the table to search in a new query, that orders by datetime ascending. I had to apply the DATE_FORMAT on the outer query because we need the datetime field to order by again.

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

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

                  相关文档推荐

                  Appending GET parameters to URL from lt;formgt; action(将 GET 参数附加到来自 lt;formgt; 的 URL行动)
                  Forcing quot;Save Asquot; dialog via jQuery GET(强制“另存为通过 jQuery GET 对话框)
                  PHP - get certain word from string(PHP - 从字符串中获取某个单词)
                  How to debug a get request in php using curl(如何使用 curl 在 php 中调试 get 请求)
                  get a # from a url in php(从 php 中的 url 获取 #)
                  PHP - include() file not working when variables are put in url?(PHP - 将变量放入 url 时,include() 文件不起作用?)

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

                      <bdo id='WbHAl'></bdo><ul id='WbHAl'></ul>
                        <tbody id='WbHAl'></tbody>

                      <tfoot id='WbHAl'></tfoot>
                    • <small id='WbHAl'></small><noframes id='WbHAl'>

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