简体   繁体   English

如何找到MySQL中所有记录的最后日期?

[英]How to find last date all record in MySQL?

how can i find last date record in MySQL. 我怎样才能找到MySQL中的最后日期记录。 i have this current date record but if i want to get a data of last day (not yesterday). 我有此当前日期记录,但是如果我想获取过去一天(不是昨天)的数据。 it is possible to get last date of record in MySQL. 有可能获得MySQL中记录的最后日期。

my current date record are there (28-11-2017).. and i want last date of record which is (25-11-2017) between this 25 to 28 there is no data . 我当前的日期记录是(28-11-2017)..我想要记录的最后日期是(25-11-2017)在25至28之间,没有数据。 i want this last date record. 我想要这个最后的日期记录。

ex. 恩。

id       DATE      PRODUCT_ID
1    2017-11-25      11
2    2017-11-25      12
3    2017-11-24      6

so last date in my table will be 25. how can i get all record of that date. 所以我表中的最后一个日期将是25。我如何获取该日期的所有记录。

link for current date table: current table 当前日期表的链接: 当前表

One option is to compare the date of each record against a non correlated subquery which finds the most recent date in the table. 一种选择是将每个记录的日期与一个不相关的子查询进行比较,该子查询在表中查找最近的日期。

SELECT *
FROM yourTable
WHERE DATE = (SELECT MAX(DATE) FROM yourTable);

If you are certain that there is only one latest date, or you can live with just a single record in the event of ties, then MySQL offers an even simpler option: 如果您确定只有一个最新日期,或者在发生联系时可以只保留一条记录,那么MySQL提供了一个更简单的选项:

SELECT *
FROM yourTable
ORDER BY DATE DESC
LIMIT 1;
SELECT DATE FROM your_table ORDER BY id DESC LIMIT 1

这将为您提供最后的约会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM