select cusnum,workname from customer,worker where cusnum=(select cusnum from inhotel where customer.cusname=inhotel.cusname) -> workname=(select workname from worker.worknum=inhotel.worknum); 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 'workname=(select workname from worker.worknum=inhotel.worknum)' at line 2 mysql>
时间: 2024-02-28 21:56:41 浏览: 51
在这个 SQL 语句中,您需要使用 JOIN 子句来联接多个表,而不是使用嵌套的子查询。您可以尝试以下 SQL 语句:
```
SELECT customer.cusnum, worker.workname
FROM customer
JOIN inhotel ON customer.cusnum = inhotel.cusnum
JOIN worker ON worker.worknum = inhotel.worknum;
```
这个语句将会从 `customer`、`inhotel` 和 `worker` 表中检索数据,并使用 `JOIN` 子句将它们连接起来。
相关问题
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;
```
这样应该可以解决问题。
阅读全文