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.
而不是显示整个日期,我只想显示日期列的前 4 个字符。
SELECT Test.Date From Test
希望日期限制为 4 个字符长
这会给你一年。
SELECT YEAR(Date) as Year FROM Test
或者你也可以使用DATE_FORMAT()
DATE_FORMAT()
SELECT DATE_FORMAT(Date, '%Y') as Year FROM Test
SELECT LEFT(Test.Date, 4) FROM Test
应该可以正常工作,假设格式是“2013-04-10”