错误 1054 (42S22):'where clause' 中的未知列 'year'

ERROR 1054 (42S22): Unknown column 'year' in 'where clause'

不确定我的专栏名称是怎么回事。

mysql> SELECT fullname FROM country WHERE year-independence > 1945;
ERROR 1054 (42S22): Unknown column 'year' in 'where clause'

这里是table限制5:

+----------------------------------------------+
| code | fullname             | continent     | region                    | area   | year-independence | population | avg-lifespan | avg-GNP   | form-government                              |
+------+----------------------+---------------+---------------------------+--------+-------------------+------------+--------------+-----------+----------------------------------------------+
| ABW  | Aruba                | North America | Caribbean                 |    193 |                 0 |     103000 |        78.40 |    828.00 | Nonmetropolitan Territory of The Netherlands |
| AFG  | Afghanistan          | Asia          | Southern and Central Asia | 652090 |              1919 |   22720000 |        45.90 |   5976.00 | Islamic Emirate                              |
| AGO  | Angola               | Africa        | Central Africa            | 124670 |              1975 |   12878000 |        38.30 |   6648.00 | Republic                                     |
| AIA  | Anguilla             | North America | Caribbean                 |     96 |                 0 |       8000 |        76.10 |     63.20 | Dependent Territory of the UK                |
| ALB  | Albania              | Europe        | Southern Europe           |  28748 |              1912 |    3401200 |        71.60 |   3205.00 | Republic                         

尝试:

SELECT fullname FROM country WHERE `year-independence` > 1945;

Certain objects within MySQL, including database, table, index, column, alias, view, stored procedure, partition, tablespace, resource group and other object names are known as identifiers. [...] If an identifier contains special characters or is a reserved word, you must quote it whenever you refer to it. [...]

根据https://dev.mysql.com/doc/refman/8.0/en/identifiers.html

The identifier quote character is the backtick (`):

mysql> SELECT * FROM `select` WHERE `select`.id > 100;

你的情况

mysql> SELECT `fullname` FROM `country` WHERE `year-independence` > 1945;

您可能已经注意到我用反引号包围了所有标识符,因为这是一个好习惯。