Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在玩我的论坛(它是自制的,不是 phpbb 或任何其他 3rd 方论坛),我想有办法说,“一年前,你发布了这个:XXXX”。
问题是,我不确定如何查询最接近一岁的东西。我觉得我需要在查询中建立一个计算,比如
PSUEDO编码了这样的东西..
SELECT *, ABS(DATE(timestamp-now)) as diff FROM table ORDER BY diff LIMIT 1- DIFF 将是我可以多接近一年前的数学。
SELECT *, ABS(DATE(timestamp-now)) as diff FROM table ORDER BY diff LIMIT 1
任何关于如何构建它的建议都会非常有帮助。
尝试
SELECT ABS((curdate() - interval 1 year) - date_column) as diff FROM table ORDER BY diff LIMIT 1