select worker.worksex customer.cussex from worker,customer where worker.worksex='男' and customer.cussex='女'; 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='男' and customer.cussex='女' at line 1
时间: 2024-02-27 22:56:24 浏览: 15
您在SELECT语句中的语法有误。在SELECT语句中,需要使用逗号分隔多个列,而不是使用空格。您可以使用以下SQL语句来实现您的需求:
```sql
SELECT worker.worksex, customer.cussex
FROM worker, customer
WHERE worker.worksex='男' AND customer.cussex='女';
```
在上述SQL语句中,我们使用逗号分隔了两个列。我们使用WHERE语句指定了连接条件,即`worker.worksex='男' AND customer.cussex='女'`。这意味着我们只返回那些`worker`表中`worksex`值为“男”,并且`customer`表中`cussex`值为“女”的行。
请注意,在这种情况下,使用JOIN语句和WHERE语句都可以实现相同的结果。但是,使用JOIN语句可以更清晰地指定连接条件,尤其在连接多个表格时非常有用。
相关问题
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 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
非常抱歉,我的上一个回答中确实存在错误。正确的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语句应该可以成功执行,并返回满足条件的记录。如果还有其他问题,请随时提出。