gpt4 book ai didi

mysql - 错误 1064 : Syntax Error MySQL

转载 作者:行者123 更新时间:2023-11-29 22:56:53 25 4
gpt4 key购买 nike

我正在做一个练习的句子,MySQL 一直在这句话中给我带来错误。

delete centros where cod_centros not in(select cod_centro from personal);

以下是表格:

CREATE TABLE CENTROS (
COD_CENTRO integer NOT NULL,
TIPO_CENTRO CHAR(1),
NOMBRE VARCHAR(30),
DIRECCION VARCHAR(26),
TELEFONO VARCHAR(10),
NUM_PLAZAS integer,
primary key (cod_centro)
);

CREATE TABLE PERSONAL (
COD_CENTRO integer NOT NULL,
DNI integer,
APELLIDOS VARCHAR(30),
FUNCION VARCHAR(15),
SALARIO integer,
primary key (cod_centro,dni),
foreign key (cod_centro) references Centros(cod_centro)
);

这里是插入内容:

INSERT INTO CENTROS VALUES (10,'S','IES El Quijote', 
'Avda. Los Molinos 25', '965-887654',538);
INSERT INTO CENTROS VALUES (15,'P','CP Los Danzantes', 'C/Las Musas s/n',
'985-112322',250);
INSERT INTO CENTROS VALUES (22,'S', 'IES Planeta Tierra', 'C/Mina 45',
'925-443400',300);
INSERT INTO CENTROS VALUES (45,'P', 'CP Manuel Hidalgo', 'C/Granada 5',
'926-202310',220);
INSERT INTO CENTROS VALUES (50,'S', 'IES Antoñete', 'C/Los Toreros 21',
'989-406090',310);


INSERT INTO PERSONAL VALUES (10,1112345,'Martínez Salas, Fernando',
'PROFESOR', 220000);
INSERT INTO PERSONAL VALUES (10,4123005,'Bueno Zarco, Elisa',
'PROFESOR', 220000);
INSERT INTO PERSONAL VALUES (10,4122025,'Montes García, M.Pilar',
'PROFESOR', 220000);

INSERT INTO PERSONAL VALUES (15,1112345,'Rivera Silvestre, Ana',
'PROFESOR', 205000);
INSERT INTO PERSONAL VALUES (15,9800990, 'Ramos Ruiz, Luis',
'PROFESOR', 205000);
INSERT INTO PERSONAL VALUES (15,8660990, 'De Lucas Fdez, M.Angel',
'PROFESOR', 205000);

INSERT INTO PERSONAL VALUES (22,7650000, 'Ruiz Lafuente, Manuel',
'PROFESOR', 220000);
INSERT INTO PERSONAL VALUES (45,43526789, 'Serrano Laguía, María',
'PROFESOR', 205000);


INSERT INTO PERSONAL VALUES (10,4480099,'Ruano Cerezo, Manuel',
'ADMINISTRATIVO', 180000);
INSERT INTO PERSONAL VALUES (15,1002345,'Albarrán Serrano, Alicia',
'ADMINISTRATIVO', 180000);
INSERT INTO PERSONAL VALUES (15,7002660,'Muñoz Rey, Felicia',
'ADMINISTRATIVO', 180000);
INSERT INTO PERSONAL VALUES (22,5502678,'Marín Marín, Pedro',
'ADMINISTRATIVO', 180000);
INSERT INTO PERSONAL VALUES (22,6600980, 'Peinado Gil, Elena',
'CONSERJE', 175000);
INSERT INTO PERSONAL VALUES (45,4163222, 'Sarro Molina, Carmen',
'CONSERJE', 175000);

我不知道该怎么办,我认为 select 的语法很好,但总是带来错误,所以我想这可能是 mysql 工作台一如既往的错误,但我不知道该怎么办!

最佳答案

您缺少 from 关键字,该关键字指示您要从哪个表中删除。

正确的解决方案:

delete from centros where cod_centros not in (select cod_centro from personal);

这是原始的、完整的单表语法:

DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM tbl_name
[WHERE where_condition]
[ORDER BY ...]
[LIMIT row_count]

引用:MySQL's DELETE Syntax Single-table syntax.

关于mysql - 错误 1064 : Syntax Error MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28680470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com