select room.roomtype,inhotel.innum,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.worknum' in 'on clause'
时间: 2024-02-28 12:57:24 浏览: 63
根据你提供的 SQL 语句,错误提示是无法识别 "worker.worknum" 这个列名,这是因为你在子查询中创建了一个名为 "workname" 的子查询表,但是你在主查询中的 JOIN 子句中使用了错误的表别名。
应该将子查询表的别名 "workname" 修改为 "worker",如下所示:
```
SELECT room.roomtype, inhotel.innum, workname
FROM room
JOIN inhotel ON inhotel.roomnum = room.roomnum
JOIN (SELECT workname, worknum FROM worker) AS worker ON inhotel.worknum = worker.worknum;
```
这样应该可以解决问题。
相关问题
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)worker on inhotel.worknum=worker.worknum; ERROR 1054 (42S22): Unknown column 'worker.worknum' in 'on clause'
根据你提供的 SQL 语句,错误提示是无法识别 "worker.worknum" 这个列名,这是因为你在子查询中创建了一个名为 "worker" 的子查询表,但是你在主查询中的 JOIN 子句中使用了错误的表别名。
应该将子查询表的别名 "worker" 修改为 "w" 或其他别名,如下所示:
```
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;
```
这样应该可以解决问题。
阅读全文