mysql - 错误 1054 (42S22) : Unknown column 'employee' in 'field list' in MySQL

标签 mysql

我不确定为什么会收到此错误消息 ERROR 1054 (42S22):“field list”中的未知列“employee”。

Employee Table Description

Employee Table

Work Table Description

Work Table

这是员工表的数据类型和插入的值:

mysql> create table employee (`employee-name` char(30), `street` char(30), 
`city` char(30));
mysql> insert into employee values ('John Smith', 'Street A', 'City 1');
mysql> insert into employee values ('Arya Stark', 'Street B', 'City 2');
mysql> insert into employee values ('Barry Allen', 'Street C', 'City 3');
mysql> insert into employee values ('Wanda Maximoff', 'Street D', 'City 4');
mysql> insert into employee values ('Raven Roth', 'Street E', 'City 5');

这是工作表的数据类型和插入的值:

mysql> create table works (`employee-name` char(30), `company-name` char(50), 
`salary` decimal(20,2));
mysql> insert into works values ('John Smith', 'MyBank', '10000');
mysql> insert into works values ('Arya Stark', 'First Bank Corporation', 
'20000');
mysql> insert into works values ('Barry Allen', 'MyBank', '17000');
mysql> insert into works values ('Wanda Maximoff', 'YourBank', '125000');
mysql> insert into works values ('Raven Roth', 'MyBank', '20000');

我从实验室实践中得到的问题是:查找姓名、街道地址、 为“第一银行”工作的所有员工的居住城市 公司并赚取超过 10,000 美元

每次我输入此内容时都会出现错误:

select employee.employee-name, employee.street, employee.city from
employee, works
where employee.employee-name=works.employee-name
and company-name = 'First Bank Corporation' and salary > 10000;
ERROR 1054 (42S22): Unknown column 'employee.employee' in 'field list'

最佳答案

您需要转义包含 - 等特殊字符的表/列名称

select employee.`employee-name`...

此外,不要再使用旧的连接样式。它在 20 年前被显式联接所取代。

select e.`employee-name`, e.street, e.city
from employee e
join works w on e.`employee-name` = w.`employee-name`
where `company-name` = 'First Bank Corporation' 
and salary > 10000

关于mysql - 错误 1054 (42S22) : Unknown column 'employee' in 'field list' in MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51435415/

相关文章:

php - 将 codeigniter 与 php 和 mysql 一起使用时,在此服务器上找不到请求的 URL 错误

php - 为表中的每一行触发 Laravel 模型事件

mysql - 如何计算嵌套连接查询的平均值?

php - 使用 PDO 和 MySQL 将 null 绑定(bind)到整数列?

php - 如何将PHP数组转换成Mysql资源

MySQL DATE_FORMAT 没有以正确的顺序输出日期

mysql - 完整连接语法中的未知列错误

mysql - Worklight 中的 .wlapp 文件部署错误

mysql - 使用 Zend_db_table 在 mySQL 中插入一个时间 + n!

mysql - 查找表中 DATETIME 差异的总和?