SELECT room.roomtype, inhotel.innum, worker.workname FROM room JOIN inhotel ON inhotel.roomnum = room.roomnum JOIN (SELECT workname, worknum FROM worker) AS w ON inhotel.worknum = w.worknumJOIN worker ON w.workname = worker.workname; ERROR 1064 (42000): 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 'worker ON w.workname = worker.workname' at line 1
时间: 2023-07-03 18:27:59 浏览: 132
根据你提供的 SQL 语句,错误提示是在第一行末尾缺少了一个空格,导致后面的 JOIN 子句被误认为是一部分的第一行语句。应该在第一行的末尾添加一个空格,修改后的 SQL 语句如下:
```
SELECT room.roomtype, inhotel.innum, worker.workname
FROM room
JOIN inhotel ON inhotel.roomnum = room.roomnum
JOIN (SELECT workname, worknum FROM worker) AS w ON inhotel.worknum = w.worknum
JOIN worker ON w.workname = worker.workname;
```
这样应该可以解决问题。
相关问题
select room.roomtype,inhotel.innum,worker.worker.workname from room -> join inhotel on inhotel.roomnum=room.roomnum -> join(select workname,worknum from worker)workname on inhotel.worknum=workname.worknum -> join worker on workname.workname=worker.worknamr; ERROR 1054 (42S22): Unknown column 'worker.worker.workname' in 'field list'
根据你提供的 SQL 语句,出现了两个错误:
1. 在第一行中,应该将 "worker.worker.workname" 修改为 "worker.workname"。
2. 在第三行中,应该将 "workname.workname" 修改为 "workname"。
修改后的 SQL 语句如下:
```
SELECT room.roomtype, inhotel.innum, worker.workname
FROM room
JOIN inhotel ON inhotel.roomnum = room.roomnum
JOIN (SELECT workname, worknum FROM worker) AS workname ON inhotel.worknum = workname.worknum
JOIN worker ON workname.workname = worker.workname;
```
这样应该可以解决问题。
select room.roomtype,inhotel.innum,worker.workname from room -> join inhotel on inhotel.roomnum=room.roomnum join (select workname from worker)workname on inhotel.worknum=worker.worknum; ERROR 1054 (42S22): Unknown column 'worker.workname' in 'field list'
根据你提供的 SQL 语句,错误提示是无法识别 "worker.workname" 这个列名,这是因为你在子查询中创建了一个名为 "workname" 的子查询表,但你没有给它一个别名,所以在主查询中无法引用它。
可以尝试修改 SQL 语句,给子查询表 "workname" 添加一个别名,例如:
```
SELECT room.roomtype, inhotel.innum, w.workname
FROM room
JOIN inhotel ON inhotel.roomnum = room.roomnum
JOIN (SELECT workname FROM worker) AS w ON inhotel.worknum = w.worknum;
```
这样应该可以解决问题。
阅读全文