我有这张桌子
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)
问题是,它没有给出同音异义词,它只给出了在表中至少有一次姓名和姓氏的人,但不是一起。
我应该如何找到同音异义词?
答案 0 :(得分:1)
您可以构建一个数组来检查多个值的出现。 例如,这是一个带子查询的变体:
SELECT * from repondant
WHERE (name,lastname) in
(
SELECT name,lastname
FROM repondant
GROUP BY name, lastname
HAVING count(array[name,lastname]) > 1
);