我有这张桌子
CREATE TABLE Repondant
matricule CHAR(8) NOT NULL, -- Roll
name VARCHAR(64) NOT NULL,
roll VARCHAR(64) NOT NULL,
email VARCHAR(80) NOT NULL,
CONSTRAINT Repondant_cc0 PRIMARY KEY (matricule),
CONSTRAINT Repondant_cc1 UNIQUE (courriel),
CONSTRAINT Repondant_matricule CHECK (matricule SIMILAR TO '[0-9]{8}'),
CONSTRAINT Repondant_nom CHECK (LENGTH(nom) > 0),
CONSTRAINT Repondant_prenom CHECK (LENGTH(prenom) > 0),
CONSTRAINT Repondant_courriel CHECK (
LOWER(courriel) SIMILAR TO
'[^][()<>:;@\,."[:space:][:cntrl:]]+(\.[^][()<>:;@\,."[:space:][:cntrl:]]+)*\@hotmail.com'
)
);
我想提出一个请求,给我一个名字,姓氏,电子邮件和卷表中所有的同名(相同的名字和相同的名字)
我试过了
(SELECT name,lastname,role,email
FROM Repondant
Where name = (SELECT name FROM Repondant GROUP BY nom HAVING COUNT(*)>1) AND
lastname = (SELECT lastname FROM Repondant GROUP BY prenom HAVING COUNT(*)>1)
问题是,它没有给出同音词,它只给出表中至少有一次名字和姓氏的人,但不总是在一起。
我该如何找到同音词?
最佳答案
可以构建一个数组来检查多个值的出现。
例如,这是一个带有子查询的变量:
SELECT * from repondant
WHERE (name,lastname) in
(
SELECT name,lastname
FROM repondant
GROUP BY name, lastname
HAVING count(array[name,lastname]) > 1
);
关于postgresql - 在PostgreSQL中查找同音异义词,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32750876/