<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 行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                  <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>