SELECT customer.cusnum, customer.cusname, customer.cussex, customer.cusid, customer.cusphone, worker.workname, worker.worksex, worker.workid, worker.worksalaryFROM customerJOIN workerON customer.cussex LIKE '%女%' AND worker.worksex LIKE '%男%'; 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 'workerON customer.cussex LIKE '%女%' AND worker.worksex LIKE '%男%'' at line 1
时间: 2024-02-27 13:56:46 浏览: 28
非常抱歉,我的上一个回答中确实存在错误。正确的SQL语句应该在FROM和JOIN之间添加一个空格,如下所示:
```
SELECT customer.cusnum, customer.cusname, customer.cussex, customer.cusid, customer.cusphone,
worker.workname, worker.worksex, worker.workid, worker.worksalary
FROM customer
JOIN worker
ON customer.cussex LIKE '%女%' AND worker.worksex LIKE '%男%';
```
这个SQL语句应该可以成功执行,并返回满足条件的记录。如果还有其他问题,请随时提出。
相关问题
select worker.worksex customer.cussex from worker,customer where worker.worksex='男',customer.cusname='女'; 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 '.cussex from worker,customer where worker.worksex='男',customer.cusname='女'' at line 1
这是因为您在SELECT语句中没有使用正确的语法来连接两个表格中的列。尝试使用JOIN语句或者WHERE语句来连接两个表格中的列,以下是一个正确的示例SQL语句:
```sql
SELECT worker.worksex, customer.cussex
FROM worker
JOIN customer
ON worker.worksex='男' AND customer.cusname='女';
```
在上述SQL语句中,我们使用JOIN语句来连接两个表格。我们使用ON关键字指定了连接条件,即`worker.worksex='男' AND customer.cusname='女'`。这意味着我们只返回那些`worker`表中`worksex`值为“男”,并且`customer`表中`cusname`值为“女”的行。
请注意,使用JOIN语句可以更清晰地指定连接条件。如果您想要使用WHERE语句来连接两个表格,请使用以下SQL语句:
```sql
SELECT worker.worksex, customer.cussex
FROM worker, customer
WHERE worker.worksex='男' AND customer.cusname='女';
```
在上述SQL语句中,我们使用逗号来连接两个表格。我们使用WHERE语句指定了连接条件,即`worker.worksex='男' AND customer.cusname='女'`。这意味着我们只返回那些`worker`表中`worksex`值为“男”,并且`customer`表中`cusname`值为“女”的行。
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>
在这个 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` 子句将它们连接起来。