JOIN表,接收NULL答案

时间:2016-02-29 19:34:50

标签: mysql join

我在编写脚本时遇到问题,我不知道我哪里错了。 我有一些表从一些txt文件填充。 之后我改变了一个表添加一个列,该列必须从JOIN的结果和另外两个表中填充。 在我当前的数据库中更具体我试图在表2中插入当前在表1和表2中的医生的ID。一个表包含id和名称,第二个表包含名称。

运行此脚本:

insert into Intermediara.id_provizoriumed
select  Medici.id_medic is not null
FROM Medici
LEFT Join Intermediara
ON Medici.Nume  COLLATE utf8_romanian_ci =Intermediara.NumeMedic;

Insert into Intermediara(id_provizoriumed)  
Select DISTINCT Pacienti.Id_pacient 
FROM Pacienti
left JOIN Intermediara
ON Pacienti.NumePacient  COLLATE utf8_romanian_ci = Intermediara.NumePacient;

将导致我的NULL答案; 请问有什么想法吗? :其中

*有关项目的更多信息:

我正在使用一个程序来创建表格:

 delimiter $$
 CREATE PROCEDURE init() 
 begin

 CREATE TABLE Medici (
 Nume VARCHAR(50),
 Prenume VARCHAR(225),
 Statut ENUM ('primar', 'specialist'),
 Specialitate VARCHAR(20),
 UNIQUE (Nume, Prenume)) DEFAULT CHARACTER SET utf8 COLLATE utf8_romanian_ci;

 ALTER TABLE Medici ADD COLUMN Id_medic int AUTO_INCREMENT PRIMARY KEY;


 ALTER TABLE Medici ADD COLUMN Tip ENUM ('primar', 'specialist') AFTER Prenume;
 ALTER TABLE Medici DROP COLUMN Statut;

 DESCRIBE Medici;


 CREATE TABLE Pacienti (
 Id_pacient int AUTO_INCREMENT NOT NULL PRIMARY KEY,
 NumePacient VARCHAR(50),
 PrenumePacient VARCHAR(100),
 UNIQUE (NumePacient, PrenumePacient))DEFAULT CHARACTER SET utf8 COLLATE utf8_romanian_ci;

 DESCRIBE Pacienti;

 CREATE TABLE Cabinete (
 Id_cabinet int AUTO_INCREMENT NOT NULL PRIMARY KEY,
 Denumire VARCHAR(50),
 UNIQUE (Denumire));

 DESCRIBE Cabinete;

 CREATE TABLE Vizite (
 IntervalData DATETIME,
 id_m int,
 id_p int,
 id_Cab int,
 FOREIGN KEY (id_m) REFERENCES Medici(Id_medic),
 FOREIGN KEY (id_p) REFERENCES Pacienti(Id_pacient),
 FOREIGN KEY (id_Cab) REFERENCES Cabinete(Id_cabinet)
 );

 DESCRIBE Vizite;

 CREATE TABLE Intermediara (
 DataVizita VARCHAR(50),
 OraIntrare TIME,
 NumePacient VARCHAR(50),
 PrenumePacient VARCHAR(50),
 NumeMedic VARCHAR(50),
 PrenumeMedic VARCHAR(50),
 Cabinet VARCHAR(50)) DEFAULT CHARACTER SET utf8 COLLATE utf8_romanian_ci;

 DESCRIBE Intermediara;
 end$$
 delimiter ; 

之后我将数据加载到Medici和Intermediara表中; 然后添加我需要的信息:

 INSERT IGNORE INTO Pacienti(NumePacient, PrenumePacient) SELECT NumePacient, PrenumePacient FROM Intermediara;
 INSERT IGNORE INTO Cabinete(Denumire) SELECT Cabinet FROM intermediara;

然后我要做的是在添加以下内容后添加Intermediara:

 ALTER TABLE Intermediara add column id_provizoriumed int collate utf8_romanian_ci;
 ALTER TABLE Intermediara add column id_provizoriupac int collate utf8_romanian_ci;
 ALTER TABLE Intermediara add column id_provizoriucab int collate utf8_romanian_ci;

通过在表中添加Medici.Nume和Intermediara.NumeMedic的JOIN,在Intermediara中添加Medici(id_medic)的id,id必须是不同的;

0 个答案:

没有答案