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.
我的数据库中有一个文本字段,其中包含 DM 日期值。这一年是一个新的领域。所以按年订购 ASC 并不难。现在我也想按日期排序。唯一的问题是,ORDER BY year ASC,ORDER BY date 不起作用。我认为是因为文本字段。是否仍然可以按年、月、日 ASC 对它们进行排序?
谢谢!
使用SUBSTRING_INDEX():
... ORDER BY year ASC, SUBSTRING_INDEX(date, '-', -1) ASC, SUBSTRING_INDEX(date, '-', 1) ASC
SUBSTRING(date, '-', -1)
-
SUBSTRING(date, '-', 1)