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.
我有一张包含事件的表格,每个事件都有一个开始和结束日期。现在我想获取(在 PHP 中仅使用 1 个 SQL)具有最新结束日期的事件和具有最早开始日期的事件。有谁知道如何做到这一点?谢谢!
如果您想要两行,而不仅仅是日期,可能要使用UNION
UNION
SELECT * from table ORDER BY end_date DESC LIMIT 1 UNION ALL SELECT * from table ORDER BY start_date ASC LIMIT 1
很容易
SELECT MIN(StartDate), Max(EndDate) From yourTable