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

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

      1. <legend id='Nm6xq'><style id='Nm6xq'><dir id='Nm6xq'><q id='Nm6xq'></q></dir></style></legend>

        SQL查询显示最近的日期?

        SQL Query to show nearest date?(SQL查询显示最近的日期?)
        <i id='9nach'><tr id='9nach'><dt id='9nach'><q id='9nach'><span id='9nach'><b id='9nach'><form id='9nach'><ins id='9nach'></ins><ul id='9nach'></ul><sub id='9nach'></sub></form><legend id='9nach'></legend><bdo id='9nach'><pre id='9nach'><center id='9nach'></center></pre></bdo></b><th id='9nach'></th></span></q></dt></tr></i><div id='9nach'><tfoot id='9nach'></tfoot><dl id='9nach'><fieldset id='9nach'></fieldset></dl></div>
        <tfoot id='9nach'></tfoot>
          <tbody id='9nach'></tbody>

          <small id='9nach'></small><noframes id='9nach'>

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

                  本文介绍了SQL查询显示最近的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我想弄清楚如何编写一个 MySQL 查询,该查询将返回最接近日期的 3 个事件.

                  I'm trying to figure out how to write a MySQL query that will return the closest 3 events in terms of date.

                  这是我的桌子:

                  EVENT_ID    EVENT_NAME     EVENT_START_DATE(DATETIME)
                  1           test           2011-06-01 23:00:00
                  2           test2          2011-06-03 23:00:00
                  3           test3          2011-07-01 23:00:00
                  4           test4          2011-08-09 23:00:00
                  5           test5          2011-06-02 23:00:00
                  6           test6          2011-04-20 23:00:00
                  

                  因此查询结果应该是 ID 的 1,2,5,因为它们与当前日期相比最接近发生..

                  So the query result should be for ID's 1,2,5 as they are the closest to occur in comparison to the current date..

                  查询应该只找到未来的事件.

                  query should find only future events.

                  推荐答案

                  SELECT event_id 
                  FROM Table 
                  ORDER BY ABS( DATEDIFF( EVENT_START_DATE, NOW() ) ) 
                  LIMIT 3
                  

                  ABS() 表示 1 天前的事件与未来 1 天的事件一样接近.如果您只想要尚未发生的事件,请执行

                  The ABS() means that an event 1 day ago is just as close as an event 1 day in the future. If you only want events that haven't happened yet, do

                  SELECT event_id 
                  FROM Table 
                  WHERE EVENT_START_DATE > NOW() 
                  ORDER BY EVENT_START_DATE 
                  LIMIT 3 
                  

                  这篇关于SQL查询显示最近的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  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 查询中包含缺失的月份)

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

                          <tbody id='XSDG0'></tbody>

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