我有一个包含以下字段的表:
State_Code School_Code Established_Year Data_Year
12 12016837383 1962 2011-12
12 12018383799 1996 2011-12
12 12024895748 2007 2011-12
12 12037849837 1987 2011-12
在这里,所有这些字段都是 VARCHAR 类型的。
我想检索 1990 年之前建立的所有学校。我触发了这个查询:
Select
School_Code,
date_format(str_to_date(Established_Year,'%y'),'%y') as Year,
date_format(str_to_date(Data_Year,'%y'),'%y') as Data_Year
from
Table1
WHERE
Established_Year < 1990;
但它返回这个:
School_Code Year Data_Year
12016837383 19 20
12037849837 19 20
我也尝试使用CONVERT
函数,如:
Select
School_Code,
Convert(Established_Year, YEAR) as Year
from
Table1
WHERE
Established_Year < 1990;
但它抛出了这个错误:
Error Code: 1064
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax
to use near 'YEAR' at line 1