错误1054(42S22):“ where子句”中的未知列“ year”

时间:2018-10-13 00:43:04

标签: mysql sql mysql-error-1054

不知道我的列名怎么了。

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

这是表格限制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                         

2 个答案:

答案 0 :(得分:1)

尝试:

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

答案 1 :(得分:1)

  

MySQL中的某些对象,包括数据库,表,索引,   列,别名,视图,存储过程,分区,表空间,资源   组和其他对象名称称为标识符。 [...] 如果   标识符包含特殊字符或为保留字,您必须   每次引用它时都要引用它。 [...]

按照https://dev.mysql.com/doc/refman/8.0/en/identifiers.html

  

标识符引号是反引号(`):

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

以您的情况

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

您可能已经注意到我用反引号将所有标识符括起来,因为这样做是一个好习惯。